Here you can find the source of getBytesFromBufferedImage(BufferedImage bi, String format)
Parameter | Description |
---|---|
bi | - the buffered image |
format | - "JPG", "PNG" or "GIF" |
public static byte[] getBytesFromBufferedImage(BufferedImage bi, String format)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.imageio.ImageIO; public class Main { /**// ww w. j a v a 2s . com * Get bytes from a specified BufferedImage, with the specified format * * @param bi * - the buffered image * @param format * - "JPG", "PNG" or "GIF" * @return */ public static byte[] getBytesFromBufferedImage(BufferedImage bi, String format) { ByteArrayOutputStream buff = new ByteArrayOutputStream(); try { ImageIO.write(bi, format, buff); byte[] bytes = buff.toByteArray(); buff.close(); return bytes; } catch (IOException ex) { ex.printStackTrace(); } return null; } }