Search in sources :

Example 1 with VideoMediaSampleJPEG

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);
}
Also used : VideoMediaSampleJPEG(cbit.vcell.export.gloworm.quicktime.VideoMediaSampleJPEG) ImageWriter(javax.imageio.ImageWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageWriteParam(javax.imageio.ImageWriteParam) ImageOutputStream(javax.imageio.stream.ImageOutputStream) IIOImage(javax.imageio.IIOImage)

Aggregations

VideoMediaSampleJPEG (cbit.vcell.export.gloworm.quicktime.VideoMediaSampleJPEG)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IIOImage (javax.imageio.IIOImage)1 ImageWriteParam (javax.imageio.ImageWriteParam)1 ImageWriter (javax.imageio.ImageWriter)1 ImageOutputStream (javax.imageio.stream.ImageOutputStream)1