use of cbit.vcell.export.gloworm.quicktime.VideoMediaSampleJPEG in project vcell by virtualcell.
the class FormatSpecificSpecs method encodeJPEG.
public static VideoMediaSampleJPEG encodeJPEG(BufferedImage bufferedImage, float compressionQuality, int width, int height, int sampleDuration, int bitsPerPixel, boolean isGrayscale) throws Exception {
ImageWriter imageWriter = ImageIO.getImageWritersBySuffix("jpeg").next();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream);
imageWriter.setOutput(imageOutputStream);
ImageWriteParam imageWriteParam = imageWriter.getDefaultWriteParam();
imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
// quality 0(very compressed, lossy) -> 1.0(less compressed,loss-less)
imageWriteParam.setCompressionQuality(compressionQuality);
IIOImage iioImage = new IIOImage(bufferedImage, null, null);
imageWriter.write(null, iioImage, imageWriteParam);
imageOutputStream.close();
imageWriter.dispose();
return new VideoMediaSampleJPEG(width, height, sampleDuration, byteArrayOutputStream.toByteArray(), bitsPerPixel, isGrayscale);
}
Aggregations