{
BufferedImage bufferedImage = new BufferedImage(imageInfo.width, imageInfo.height, BufferedImage.TYPE_INT_ARGB);
bufferedImage.setRGB(0, 0, imageInfo.width, imageInfo.height, pixels, 0, imageInfo.width);
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();
ColorModel colorModel = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
ImageTypeSpecifier imageTypeSpecifier = new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(1, 1));
writeParam.setDestinationType(imageTypeSpecifier);
writeParam.setSourceBands(new int[] {0, 1, 2});
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
float q = 1.0f;
if (quality != null)
q = quality.floatValue();
writeParam.setCompressionQuality(q);
DAByteArrayOutputStream buffer = new DAByteArrayOutputStream();
writer.setOutput(new MemoryCacheImageOutputStream(buffer));
IIOImage ioImage = new IIOImage(bufferedImage, null, null);