Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Turning non-transparent jpg into transparent png

 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPEG does not support transparency. You'd need to use PNG instead.
 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh right, I forgot to add that part...yes, I would want to convert it to a png also.
 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips! I'll check it out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic