Here you can find the source of imageToByte(BufferedImage bi, String format)
public static byte[] imageToByte(BufferedImage bi, String format) throws IOException
//package com.java2s; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.imageio.ImageIO; public class Main { public static byte[] imageToByte(BufferedImage bi, String format) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bi, format, baos); return baos.toByteArray(); }// ww w. ja v a 2s . c o m }