Converts a byte Array to an BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Convert

Description

Converts a byte Array to an BufferedImage

Demo Code


//package com.java2s;

import java.awt.image.BufferedImage;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;

public class Main {
    /**/*from   w w  w  .ja  v a2  s. c o m*/
     * Converts a byte Array to an {@link BufferedImage}
     *
     * @param imgBytes
     * @return
     * @throws IOException
     */
    public static BufferedImage byteArrayToImage(byte[] imgBytes)
            throws IOException {
        BufferedImage bufferedImage = null;
        InputStream inputStream = new ByteArrayInputStream(imgBytes);
        bufferedImage = ImageIO.read(inputStream);
        return bufferedImage;
    }
}

Related Tutorials