wood burning stoves 2.0*
The moose likes Java in General and the fly likes Turning non-transparent jpg into transparent png Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Turning non-transparent jpg into transparent png" Watch "Turning non-transparent jpg into transparent png" New topic
Author

Turning non-transparent jpg into transparent png

Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
Is there a way in Java to convert the following jpg image:
here

into a transparent png by making a color (say...black?) transparent? I have little to no familiarity with anything dealing with manipulating imagery in Java. Any tips on where to start looking?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41582
    
  54
JPEG does not support transparency. You'd need to use PNG instead.


Ping & DNS - my free Android networking tools app
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
Oh right, I forgot to add that part...yes, I would want to convert it to a png also.
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
I have this bit of .NET code that I believe does what I'm looking to do, but I don't know where to start in terms of converting the functionality into a Java method:

Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Take a look at java.awt.BufferedImage. By setting up two BufferedImages, you can analyse each pixel in the first (the original image), and set the transparency (alpha channel) in the other. Pixels have the RGBA values, so the last octet in an int is the alpha (transparency) value.

Oh, and look into javax.imageio.ImageIO for importing BufferedImages from/exporting BufferedImages to files.
[ December 10, 2008: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
Thanks for the tips! I'll check it out.
 
Don't get me started about those stupid light bulbs.
 
subject: Turning non-transparent jpg into transparent png