// encoder.setJPEGEncodeParam(encpar);
// encoder.encode(image);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageWriter writer = ImageIO.getImageWritersByFormatName( "jpg" ).next();
ImageOutputStream ios = ImageIO.createImageOutputStream( out );
writer.setOutput( ios );
//ImageWriteParam param = writer.getDefaultWriteParam();
//log.debug("Logs "+param.getCompressionType());
//param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
//param.setCompressionQuality(ClientConnectionBean.imgQualityDefault);
ImageWriteParam iwparam = new JPEGImageWriteParam( Locale.getDefault() );
iwparam.setCompressionMode( ImageWriteParam.MODE_EXPLICIT ) ;
iwparam.setCompressionQuality( ClientConnectionBean.imgQualityDefault );
writer.write( null, new IIOImage(image, null, null), null );
ios.flush();
writer.dispose();
ios.close();
imageScreen.flush();
byte[] payload = out.toByteArray();