views:

1620

answers:

3

Hi

In my Java application I would like to download a JPEG, transfer it to a PNG and do something with the resulting bytes.

I am almost certain I remember a library to do this exists, I cannot remember its name.

Can anyone help me?

Thanks!

+4  A: 

javax.imageio should be enough. Put your JPEG to BufferedImage, then save it with:

File file = new File("newimage.png");
ImageIO.write(myJpegImage, "png", file);
Max
+3  A: 

ImageIO can be used to load JPEG files and save PNG files (also into a ByteArrayOutputStream if you don't want to write to a file).

Joachim Sauer
+4  A: 

This is what I ended up doing, I was thinking toooo far outside of the box when I asked the question..

// these are the imports needed
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import java.io.ByteArrayOutputStream;

// this reads a jpeg from a inputFile
BufferedImage bufferedImage = ImageIO.read(new File(inputFile));

// this writes the bufferedImage back to outputFile
ImageIO.write(bufferedImage, "png", new File(outputFile));

// this writes the bufferedImage into a byte array called resultingBytes
ByteArrayOuputStream byteArrayOut = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", byteArrayOut, byteArrayOut);
byte[] resultingBytes = byteArrayOut.tobyteArray();
adam