Here you can find the source of getBytes(BufferedImage image)
public static byte[] getBytes(BufferedImage image)
//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 { public static byte[] getBytes(BufferedImage image) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {//from w w w . j a v a 2 s . com ImageIO.write(image, "png", outputStream); } catch (IOException e) { throw new RuntimeException(e); } return outputStream.toByteArray(); } }