• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Turning non-transparent jpg into transparent png

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tips! I'll check it out.
 
reply
    Bookmark Topic Watch Topic
  • New Topic