• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Java Image Processing Troubles

New Here ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

I'm a beginner at integrating java into coldfusion. I have a component which will scale and crop an image, but I'd also like to run it through a color-filter to turn it grayscale. I've found methods but can't seem to get them to work, any tips?

P.S.: I'm using the 'java.awt.image' classes
TOPICS
Advanced techniques

Views

318

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

Could we see your methods in action?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

LATEST
<cffunction name="getFileObject" access="private" hint="Loads a file into memory so it's ready for manipulation">
<cfargument name="filePath" type="string" required="yes" hint="Absolute path the the file you'd like to load.">

<!--- Loading the file into memory--->
<cfset var result=CreateObject("java","java.io.File")>
<cfset result.init(filePath)>

<!---Return the file object to the caller function--->
<cfreturn result>
</cffunction>

<cffunction name="memberPicture" output="true" hint="Turns a file into the correct size, color, and format for the site.">
<cfargument name="sourcePath" type="string" required="yes" hint="Absolute path to the source image">
<cfargument name="destPath" type="string" required="yes" hint="Absolute path to the place you want to put the processed image.">
<cfargument name="new_width" type="numeric" required="no" default="220">
<!---Load class to hold the input image in--->
<cfset var ImageIO=CreateObject("java","javax.imageio.ImageIO")>
<!---Load class to hold the output image--->
<cfset var jbiDest=CreateObject("java","java.awt.image.BufferedImage")>
<!---Load class that will be transforming the image--->
<cfset var jatTransformer=CreateObject("java","java.awt.geom.AffineTransform")>

<!---Call our local function to create the input and destination file streams--->
<cfset var jFileIn=getFileObject(sourcePath)>
<cfset var jFileOut=getFileObject(destPath)>

<!---Load the input file into the imageIO object--->
<cfset var jbiSource=ImageIO.read(jFileIn)>


<!---See how big the input file is--->
<cfset var jFileIn_height=jbiSource.getHeight()>
<cfset var jFileIn_width=jbiSource.getWidth()>

<!---Figure out the scales for our output file--->
<cfset var scale=ARGUMENTS.new_width/jFileIn_width>
<cfset var jFileOut_height=jFileIn_height * scale>
<cfset var jFileOut_width=ARGUMENTS.new_width>

<!---Create a place to put the destination image object--->
<cfset jbiDest.init(JavaCast("int",jFileOut_width),JavaCast("int",jFileOut_height),jbiSource.getType())>

<!---Tell the transformer object how we want to transform the image--->
<cfset jatTransformer.setToScale(scale,scale)>

<!---User the transformer to transform the input file so that it's ready to be outputted--->
<cfset jbiDest.getGraphics().drawRenderedImage(jbiSource,jatTransformer)>

<!---Convert the image into a 'jpeg' format and save it to the desired destination--->
<cfset ImageIO.write(jbiDest, "jpeg", jFileOut)>

</cffunction>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation