By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,541 Members | 1,109 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,541 IT Pros & Developers. It's quick & easy.

image to jpg

P: n/a
I managed to do this with ImageIO, example taken from:

watch out for the javascript errors, but good site with loads of image and
java stuff...

This was the code I used.

// temp output file bit
public void outputFile() throws Exception{
//start of the output stuff

FileOutputStream fo = new FileOutputStream("myImg.jpg");//name of image

BufferedOutputStream bo = new BufferedOutputStream(fo);//set to buffered

//destination here is the name of the raster reference. referencing a
ImageIO.write(destination, "jpeg", bo);//write the file out using ImageIO
to the HD

//end of the output stuff
// EOF temp outupt file bit

hope this helps


From: "Murray" <pa***>
Subject: Re: Saving a BufferedImage as a JPEG
Date: 07 May 2004 16:49
"Michael Johnston" <mi****************> wrote in message
news:72************************** om...
I am saving a BufferedImage as a JPEG file under Windows XP.
I am using the JAI JPEGImageEncoder class.
The JPEG is saved as CMYK but I need RGB.
I cannot figure out how to get RGB. Any help?

Where is the BufferedImage coming from? If you're creating the object
yourself, try using INT_RGB imageType instead of the default ARGB.

image = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);

It might also be worth trying this:

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
encoder.encode(img, param);

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.