Java BufferedImage to Byte Array toByteArray(BufferedImage image, String formatName)

Here you can find the source of toByteArray(BufferedImage image, String formatName)

Description

to Byte Array

License

Open Source License

Declaration

public static byte[] toByteArray(BufferedImage image, String formatName)
            throws IOException 

Method Source Code

//package com.java2s;

import java.awt.image.BufferedImage;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Main {
    public static byte[] toByteArray(BufferedImage image, String formatName)
            throws IOException {
        ByteArrayOutputStream os = new ByteArrayOutputStream();

        ImageIO.write(image, formatName, os);
        byte[] data = os.toByteArray();
        os.close();//from w  w  w  .j ava 2s .  c  o m

        return data;
    }
}

Related

  1. imageToBytes(BufferedImage img, String formatName)
  2. toArrayByte(BufferedImage image)
  3. toByteArray(BufferedImage image)
  4. toByteArray(BufferedImage image, float quality)
  5. toByteArray(BufferedImage image, String extension)
  6. toByteArray(BufferedImage img, String imageFileType)
  7. toByteArray(BufferedImage org)
  8. toByteArray(final BufferedImage image, final String format)
  9. toByteArray(RenderedImage image)