// instantiate an ImageWriteParam object with default compression options
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(0.75f);
writer.setOutput(new MemoryCacheImageOutputStream(thumbOutStream));
IIOImage thumbimage = new IIOImage(convertedThumbImage, null, null);
writer.write(null, thumbimage, iwp);
pngIn.reset();
ByteArrayOutputStream slideOutStream = new ByteArrayOutputStream();
BufferedImage slidebi = ImageIO.read(pngIn);
BufferedImage convertedSlideImage = createThumbnail(slidebi, 640, 400, true);
slideFile.setWidth(convertedSlideImage.getWidth());
slideFile.setHeight(convertedSlideImage.getHeight());
writer.setOutput(new MemoryCacheImageOutputStream(slideOutStream));
IIOImage slideimage = new IIOImage(convertedSlideImage, null, null);
writer.write(null, slideimage, iwp);
pngIn.reset();
ByteArrayOutputStream previewOutStream = new ByteArrayOutputStream();
BufferedImage previewbi = ImageIO.read(pngIn);
BufferedImage convertedPreviewImage = createThumbnail(previewbi, 320, 200, true);
previewFile.setWidth(convertedPreviewImage.getWidth());
previewFile.setHeight(convertedPreviewImage.getHeight());
writer.setOutput(new MemoryCacheImageOutputStream(previewOutStream));
IIOImage previewimage = new IIOImage(convertedPreviewImage, null, null);
writer.write(null, previewimage, iwp);
thumbFile.setContentType("image/jpeg");
slideFile.setContentType("image/jpeg");