Search in sources :

Example 1 with MeasuredOutputStream

use of com.bric.io.MeasuredOutputStream in project screenbird by adamhub.

the class Frame method writeJPEG.

/** Writes a JPEG image to a given OutputStream
     * 
     * @param bi an image
     * @param quality the quality (between zero and one)
     * @return the amount of bytes written
     */
protected static long writeJPEG(OutputStream out, BufferedImage bi, float quality) throws IOException {
    MeasuredOutputStream mOut = new MeasuredOutputStream(out);
    MemoryCacheImageOutputStream iOut = null;
    iOut = new MemoryCacheImageOutputStream(mOut);
    ImageWriter iw = (ImageWriter) ImageIO.getImageWritersByMIMEType("image/jpeg").next();
    ImageWriteParam iwParam = iw.getDefaultWriteParam();
    iwParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwParam.setCompressionQuality(quality);
    iw.setOutput(iOut);
    IIOImage img = new IIOImage(bi, null, null);
    iw.write(null, img, iwParam);
    return mOut.getBytesWritten();
}
Also used : MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) MeasuredOutputStream(com.bric.io.MeasuredOutputStream) ImageWriter(javax.imageio.ImageWriter) ImageWriteParam(javax.imageio.ImageWriteParam) IIOImage(javax.imageio.IIOImage)

Aggregations

MeasuredOutputStream (com.bric.io.MeasuredOutputStream)1 IIOImage (javax.imageio.IIOImage)1 ImageWriteParam (javax.imageio.ImageWriteParam)1 ImageWriter (javax.imageio.ImageWriter)1 MemoryCacheImageOutputStream (javax.imageio.stream.MemoryCacheImageOutputStream)1