From byte[] that rapp an image file TO a byte[] of the same file but in jpg
Hello
I've a byte[]. These bytes are of an image file with any extension (gif, png, jpeg etc.)
I want to convert these byte[] in another byte[] array that has the same image but represented in jpeg format.
I've found something like
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder .... and others
but I've a lot of confusion about what are the steps to do something like that..
Someone can post some sample code?
thanks a lot guys
giada
[500 byte] By [
giadaa] at [2007-11-27 0:29:39]

Check out [url=http://forum.java.sun.com/thread.jspa?threadID=5150759]this thread[/url]. I had a similar problem awhile back, and that thread has pretty much everything you'd need to know about working with byte[] image streams. Although my problem was not exactly what yours is, I know the answer to your problem lies in that thread. Read it over a bit, and check out the links provided.
In fact, this seems to be what you need:
byte buffer[] = getImage(); //whatever you use to retrieve the byte[]
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new ByteArrayInputStream(buffer));
BufferedImage image =decoder.decodeAsBufferedImage()
This gives you a BufferedImage, image, that you can then write as a jpeg image.
Message was edited by:
Djaunl
Thanks for your reply
Yes but this create a BufferedImage from a byte[] of a jpg file.
I don't want to decode the byte[] of an jpg image. I want to decode the byte[] of any image type and encode these in a jpg format
(Maybe I don't understand your reply, some code is appreciated)
giadaa at 2007-7-11 22:32:14 >
