public static byte[] encode(BufferedImage image, String format,
                                float quality) throws IOException {
        ImageEncoder imageEncoder 
            = ImageEncoderFactory.newInstance(format, quality);
        return imageEncoder.encode(image);