Here you can find the source of imageToByte(BufferedImage image)
Parameter | Description |
---|---|
image | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] imageToByte(BufferedImage image) throws IOException
//package com.java2s; //License from project: Apache License import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.imageio.ImageIO; public class Main { /**//from w w w . ja v a2s.c o m * image to byte * @param image * @return * @throws IOException */ public static byte[] imageToByte(BufferedImage image) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(image, "png", out); try { return out.toByteArray(); } finally { if (out != null) { out.close(); } } } }