Here you can find the source of toArrayByte(BufferedImage image)
public static byte[] toArrayByte(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[] toArrayByte(BufferedImage image) { byte[] bytes = new byte[] {}; try {//from w w w . j a v a 2 s .co m ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); baos.flush(); bytes = baos.toByteArray(); baos.close(); } catch (IOException e) { System.out.printf("Falha ao tentar converter uma imagem em bytes: %s.\n", e.getMessage()); } return bytes; } }