use of com.github.jaiimageio.jpeg2000.impl.J2KImageWriterSpi in project alliance by codice.
the class NitfPreStoragePlugin method renderToJpeg2k.
private byte[] renderToJpeg2k(final BufferedImage bufferedImage) throws IOException {
BufferedImage imageToCompress = bufferedImage;
if (bufferedImage.getColorModel().getNumComponents() == ARGB_COMPONENT_COUNT) {
imageToCompress = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = imageToCompress.createGraphics();
g.drawImage(bufferedImage, 0, 0, null);
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
J2KImageWriter writer = new J2KImageWriter(new J2KImageWriterSpi());
J2KImageWriteParam writeParams = (J2KImageWriteParam) writer.getDefaultWriteParam();
writeParams.setLossless(false);
writeParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParams.setCompressionType("JPEG2000");
writeParams.setCompressionQuality(0.0f);
ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
writer.setOutput(ios);
writer.write(null, new IIOImage(imageToCompress, null, null), writeParams);
writer.dispose();
ios.close();
return os.toByteArray();
}
Aggregations