Java BufferedImage to Byte Array getByteArray(File file)

Here you can find the source of getByteArray(File file)

Description

get Byte Array

License

Open Source License

Declaration

public static byte[] getByteArray(File file) throws IOException 

Method Source Code


//package com.java2s;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Main {
    public static byte[] getByteArray(File file) throws IOException {
        BufferedImage originalImage = ImageIO.read(file);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(originalImage, "jpg", baos);
        baos.flush();/* w w  w .  j av  a2 s  .  c  om*/
        return baos.toByteArray();
    }
}

Related

  1. getByteArray(RenderedImage image, String formatName)
  2. getByteBuffer(BufferedImage bufferedImage)
  3. getByteBufferToImage(ByteBuffer buffer, int width, int height)
  4. getByteImage(BufferedImage imagem)