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

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

Description

get the image from the given bytes

License

Apache License

Parameter

Parameter Description
imageBytes a parameter

Exception

Parameter Description
IOException an exception

Return

the image

Declaration

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

Method Source Code

//package com.java2s;
/**//from  ww w  . java2 s.  co  m
 * Copyright (c) 2013-2016 BITPlan GmbH
 *
 * http://www.bitplan.com
 *
 * This file is part of the Opensource project at:
 * https://github.com/BITPlan/com.bitplan.mjpegstreamer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;

public class Main {
    /**
     * get the image from the given bytes
     * @param imageBytes
     * @return the image
     * @throws IOException
     */
    public static BufferedImage getImage(byte[] imageBytes)
            throws IOException {
        ByteArrayInputStream jpgIn = new ByteArrayInputStream(imageBytes);
        BufferedImage bufImg = getImage(jpgIn);
        return bufImg;
    }

    /**
     * get the Image from the given Input Stream
     * @param jpgIn
     * @return the image
     * @throws IOException
     */
    public static BufferedImage getImage(InputStream jpgIn)
            throws IOException {
        BufferedImage bufImg = ImageIO.read(jpgIn);
        jpgIn.close();
        return bufImg;
    }
}

Related

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