We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › save() jpg quality to low
Page Index Toggle Pages: 1
save() jpg quality to low (Read 646 times)
save() jpg quality to low
Oct 29th, 2009, 12:43am
 
I am still making a program  which resizes an image and saves it as .jpg

quastion:
when using save() is there a way to use a higher jpg quality? The standard quality is kind of low.
Or is there another way to make high quality jpg images.
Bmp quality is good, but is has to be jpg.

Hope someone can help.
Re: save() jpg quality to low
Reply #1 - Oct 29th, 2009, 1:54am
 
save() uses the ImageIO.write() Java call to do the save.
It uses an arbitrary image writer (chosen internally by Java), depending on file extension, to do the job. With a default, medium quality.
There is a page explaining how to do the save yourself with chosen quality: Adjust JPEG image compression quality when saving images in Java.
In Processing, the core of save() is:
Code:
    try {
BufferedImage bimage =
new BufferedImage(width, height, (format == ARGB) ?
BufferedImage.TYPE_INT_ARGB :
BufferedImage.TYPE_INT_RGB);
bimage.setRGB(0, 0, width, height, pixels, 0, width);
File file = new File(path);
String extension = path.substring(path.lastIndexOf('.') + 1);

ImageIO.write(bimage, extension, file);
} catch (Exception e) {
e.printStackTrace();
throw new IOException("image save failed.");
}
}

so you can do your own save() based on this code, using the given improvement.
Page Index Toggle Pages: 1