• Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphics.drawImage not using specified background color  RSS feed

 
Sam Ingrassia
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sam Ingrassia
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!