Java BufferedImage to Byte Array toArrayByte(BufferedImage image)

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

Description

to Array Byte

License

Open Source License

Declaration


public static byte[] toArrayByte(BufferedImage image) 

Method Source Code

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

Related

  1. imageToByte(BufferedImage img)
  2. imageToByteArray(BufferedImage o)
  3. imageToBytes(BufferedImage image, String encoding)
  4. imageToBytes(BufferedImage image, String imageFormat)
  5. imageToBytes(BufferedImage img, String formatName)
  6. toByteArray(BufferedImage image)
  7. toByteArray(BufferedImage image, float quality)
  8. toByteArray(BufferedImage image, String extension)
  9. toByteArray(BufferedImage image, String formatName)