aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Graphics.drawImage not using specified background color Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Graphics.drawImage not using specified background color" Watch "Graphics.drawImage not using specified background color" New topic
Author

Graphics.drawImage not using specified background color

Sam Ingrassia
Greenhorn

Joined: Feb 18, 2009
Posts: 4
Thanks to everyone in advance -

I have created an image resizing class, with a crop method. The cropping works great, the issue that I am having is the background color that i specify in the drawImage function of Graphics is not working correctly, it defaults everything to black. Here is the code below that I am working with, I have also included the SaveTo method so you can see how I am saving as well

Thanks,

Sam


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Try using BufferedImage.TYPE_INT_ARGB. The background is only used with transparency, and BufferedImage.TYPE_INT_RGB does not support that.

Also, there is an error in your code. You draw a part of the image of size OutputWidth x OutputHeight, but a part of that rectangle is outside your actual image. You should add SourceX and SourceY to the rectangle to draw:
Also, don't forget to dispose() your Graphics object.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Sam Ingrassia
Greenhorn

Joined: Feb 18, 2009
Posts: 4
Thank you very much for the reply -


So I dropped in TYPE_INT_ARGB in and it gave me the error "java.io.IOException: Image can not be encoded with compression type BI_RGB", after looking into that a bit, I set the "getImageWritersByFormatName" to use PNG instead of BMP (I guess BMP doesnt support transparency, or it does, but no one ever implements it). This time though the image that I am overlaying colors were modified and the background is still black : )

Any suggestions?

Thanks,

Sam
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Graphics.drawImage not using specified background color
 
Similar Threads
Help for java ImageIO API for PNG Images
Exception in writing to the response output stream through the included jsp
Upload and Resize Advice
Adjusting the size of an image (jpg)?
ImageIO.write - TIF and BMP - Zero bytes