It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Pixels to PNG Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Pixels to PNG" Watch "Pixels to PNG" New topic

Pixels to PNG

Ken Wilson

Joined: Jan 19, 2001
Posts: 4
Can someone please point me in the right direction? If I have an array containing image data (pixels), how can I convert this to an graphic file (e.g. PNG or JPG)?
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You have to know how the pixels are encoded into the file, i.e. the file format, plus if there are any headers, etc. Luckily, you don't (usually) have to write your own encoding functions... sun provides a JPEG encoder in the com.sun.image.codec.jpeg package (it comes with the JDK... look here to get info ), and I am sure someone has written a PNG encoder... look around on the net with a good search engine for java & PNG...
The JAI (Java Advanced Imaging) API may also provide what you need ( I found it while looking around Sun for Java and PNG ), as well as possibly the Java2D API... you can find (exhaustive) references to these if you go to Sun and type PNG into their site search.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Pixels to PNG
It's not a secret anymore!