Here you can find the source of bufferedImageToByte(BufferedImage originalImage)
public static byte[] bufferedImageToByte(BufferedImage originalImage) throws IOException
//package com.java2s; //License from project: Open Source License import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.*; public class Main { public static byte[] bufferedImageToByte(BufferedImage originalImage) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, "jpg", baos); baos.flush();// w w w . jav a 2s .c om byte[] imageInByte = baos.toByteArray(); baos.close(); return imageInByte; } }