2009-11-01 16:16:54 UTC
Not sure if I understand what you are asking about, but there are two sources for quality loss in the example above. The first is rescaling (which does not involve compression), and the second is saving as JPEG (which involves lossy compression).
Rescaling can be done using the Resample operation. The resample quality depends on the filter type, I recommend using the "Lanczos3" type if you want high quality rescaling. From the javadoc example:
Resample resample = new Resample();
resample.setInputImage(image);
resample.setSize(image.getWidth() * 3 / 2, image.getHeight() * 3 / 2);
resample.setFilter(Resample.FILTER_TYPE_LANCZOS3);
resample.process();
PixelImage scaledImage = resample.getOutputImage();
JIU doesn't have functionality to save to JPEG (unless I overlooked it), so I have used javax.imageio.ImageWriter for this. If you have an ImageWriter object it is possible to choose the JPEG quality by using the ImageWriteParam object, something like this:
/* Assume imageWriter is an ImageWriter */
ImageWriteParam param = imageWriter.getDefaultWriteParam();
if (param instanceof JPEGImageWriteParam) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(0.9);
}
/* Assume image is an IIOImage */
imageWriter.write(null, image, param);
Did this answer your question?