Java BufferedImage to Byte Array imageToByte(BufferedImage image)

Here you can find the source of imageToByte(BufferedImage image)

Description

image to byte

License

Apache License

Parameter

Parameter Description
image a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static byte[] imageToByte(BufferedImage image) throws IOException 

Method Source Code

//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();
            }
        }
    }
}

Related

  1. getBytesFromImage(String fileIn, String fileOut)
  2. getBytesPerPixel(int bufferedImageType)
  3. image2Bytes(BufferedImage image)
  4. image2Bytes(File f)
  5. imageToByte(BufferedImage bi, String format)
  6. imageToByte(BufferedImage img)
  7. imageToByteArray(BufferedImage o)
  8. imageToBytes(BufferedImage image, String encoding)
  9. imageToBytes(BufferedImage image, String imageFormat)