1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| // read original image
BufferedImage input = ImageIO.read(new File("test.png"));
// create writer
ImageWriter writer = ImageIO.getImageWritersBySuffix("jpg").next();
ImageOutputStream ios = ImageIO.createImageOutputStream(new File("test.jpg"));
writer.setOutput(ios);
// create writer parameters
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(0.25f);
// write image
writer.write(null, new IIOImage(input, null, null), param);
writer.dispose(); |