Java BufferedImage from Byte Array getImage(byte[] imageBytes)

Here you can find the source of getImage(byte[] imageBytes)

Description

Get a buffered image of the image bytes

License

Open Source License

Parameter

Parameter Description
imageBytes a parameter

Exception

Parameter Description
IOException an exception

Return

buffered image or null

Declaration

public static BufferedImage getImage(byte[] imageBytes) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;

import java.io.IOException;

import javax.imageio.ImageIO;

public class Main {
    /**//from   w ww  .  j a va2s .  c o  m
     * Get a buffered image of the image bytes
     * 
     * @param imageBytes
     * @return buffered image or null
     * @throws IOException
     * @since 1.1.2
     */
    public static BufferedImage getImage(byte[] imageBytes) throws IOException {

        BufferedImage image = null;

        if (imageBytes != null) {
            ByteArrayInputStream stream = new ByteArrayInputStream(imageBytes);
            image = ImageIO.read(stream);
            stream.close();
        }

        return image;
    }
}

Related

  1. fromByteIntensity(BufferedImage image, byte[] bytes)
  2. fromIntIntensityScaled(int width, int height, int[] data)
  3. fromIntRGB(BufferedImage image, int[] rgb)
  4. getBufferedImage(byte[] imageBytes)
  5. getImage(byte[] bytes)
  6. getImage(byte[] imageBytes)