Java PNG pngToImage(byte[] imageData)

Here you can find the source of pngToImage(byte[] imageData)

Description

Converts a byte array into an image.

License

Open Source License

Parameter

Parameter Description
imageData The byte array of the data to convert.

Exception

Parameter Description
IOException an exception

Return

Image The image instance created from the byte array

Declaration

static public BufferedImage pngToImage(byte[] imageData) throws IOException 

Method Source Code

//package com.java2s;
/*/*from w  w  w .  j a  v a2s.  c  o m*/
 *  Tiled Map Editor, (c) 2004-2008
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Adam Turk <aturk@biggeruniverse.com>
 *  Bjorn Lindeijer <bjorn@lindeijer.nl>
 */

import java.awt.image.BufferedImage;

import java.io.ByteArrayInputStream;

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

public class Main {
    /**
     * Converts a byte array into an image. The byte array must include the
     * image header, so that a decision about format can be made.
     *
     * @param imageData The byte array of the data to convert.
     * @return Image The image instance created from the byte array
     * @throws IOException
     * @see java.awt.Toolkit#createImage(byte[] imagedata)
     */
    static public BufferedImage pngToImage(byte[] imageData) throws IOException {
        return ImageIO.read(new ByteArrayInputStream(imageData));
    }
}