K
k0m0r
Hi.
I've been trying to solve it myself, but I give up.
I need to convert BufferedImage to byte[]. I'm using
com.sun.imageio.plugins.jpeg.JPEGImageWriter and everything works
perfect, expect the writer keeps compressing all images, and the
quality of output is really poor
My code is:
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageOutputStream imgOut = ImageIO.createImageOutputStream(out);
Iterator writerIter = ImageIO.getImageWritersByFormatName("jpg");
ImageWriter writer = (ImageWriter) writerIter.next();
// now the writer is com.sun.imageio.plugins.jpeg.JPEGImageWriter
writer.setOutput(imgOut);
writer.prepareWriteSequence(null);
for(...) {
BufferedImage image = (...)
IIOImage iioImage = new IIOImage(image, null, null);
writer.write(iioImage);
out.reset();
(...) // saving the byte array somewhere
}
writer.endWriteSequence();
imgOut.flush();
writer.dispose();
imgOut.close();
Please help - how can I set the JPEG compression value to the highest
quality?
Or maybe 95-97% of the original quality?
Thanx a lot in advance,
k0m0r
I've been trying to solve it myself, but I give up.
I need to convert BufferedImage to byte[]. I'm using
com.sun.imageio.plugins.jpeg.JPEGImageWriter and everything works
perfect, expect the writer keeps compressing all images, and the
quality of output is really poor
My code is:
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageOutputStream imgOut = ImageIO.createImageOutputStream(out);
Iterator writerIter = ImageIO.getImageWritersByFormatName("jpg");
ImageWriter writer = (ImageWriter) writerIter.next();
// now the writer is com.sun.imageio.plugins.jpeg.JPEGImageWriter
writer.setOutput(imgOut);
writer.prepareWriteSequence(null);
for(...) {
BufferedImage image = (...)
IIOImage iioImage = new IIOImage(image, null, null);
writer.write(iioImage);
out.reset();
(...) // saving the byte array somewhere
}
writer.endWriteSequence();
imgOut.flush();
writer.dispose();
imgOut.close();
Please help - how can I set the JPEG compression value to the highest
quality?
Or maybe 95-97% of the original quality?
Thanx a lot in advance,
k0m0r