• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Executing the clearRect() method seems to be the solution. Thanks a lot !
reply
    Bookmark Topic Watch Topic
  • New Topic