• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting PNG/GIF to JPEG: alpha channel gets black background color

 
Jeroen De Schutter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid in don't quite understand how imaging in Java works ...
I am storing thumbnails of image files in a database. The thumbnails are always in JPEG format. When i want to store images with transparency (GIFs or PNGs) the "background color" of the alpha channel is always rendered black in the JPEG. I'd like it to become white, but I have no idea how.

I have already tried to set the background color of the Graphics2D object to white, but without visble results.

This is my code


Please note that my app runs on OC4J 10.1.2, so i'm limited to JDK 1.4
 
Brian Cole
Author
Ranch Hand
Posts: 900
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeroen De Schutter wrote:When i want to store images with transparency (GIFs or PNGs) the "background color" of the alpha channel is always rendered black in the JPEG. I'd like it to become white, but I have no idea how.

I have already tried to set the background color of the Graphics2D object to white, but without visble results.


Setting the background color of the Graphics object will have no effect unless you actually do some drawing that uses the background color. For instance you could do a vG2d.clearRect(...) before the vG2d.drawImage(...).

[edit: I had originally written vG2d.fillRect(...) but that uses the foreground color.]
 
Jeroen De Schutter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Executing the clearRect() method seems to be the solution. Thanks a lot !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic