Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
public BufferedImage compress(PlanarImage img) {
// not sure you actually need this line -
// try encoding the PlanarImage directly
BufferedImage buffImg = img.getAsBufferedImage();
// The image to return
BufferedImage retImg = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param;
param = encoder.getDefaultJPEGEncodeParam(buffImg);
param.setQuality(0.5F, true);
try {
// encode the image
encoder.encode(buffImg, param);
// write the image into a byte[] array
byte[] compressedData = out.toByteArray();
// now read that data back into a BufferedImage
ByteArrayInputStream bais = new ByteArrayInputStream(compressedData);
retImg = javax.imageio.ImageIO.read(bais);
}
catch (IOException e) {
e.printStackTrace(System.err);
}
return retImg;
}
BufferedImage bi ...
PlanarImage pi = PlanarImage.wrapRenderedImage(bi) ;