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();
}
Aggregations