• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Graphics.drawImage not using specified background color

 
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


 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
    Bookmark Topic Watch Topic
  • New Topic