Java BufferedImage Create getBufferedImageFromPath(String path)

Here you can find the source of getBufferedImageFromPath(String path)

Description

Loads a BufferedImage from a given file path

License

Open Source License

Parameter

Parameter Description
path The path to the image

Exception

Parameter Description
IOException If the file could not be read

Return

A BufferedImage

Declaration

public static BufferedImage getBufferedImageFromPath(String path) throws IOException 

Method Source Code

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

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

public class Main {
    /**/*from   w  w  w  . ja va 2  s.  co  m*/
     * Loads a BufferedImage from a given file path
     * 
     * @param path
     *            The path to the image
     * @return A BufferedImage
     * @throws IOException
     *             If the file could not be read
     */
    public static BufferedImage getBufferedImageFromPath(String path) throws IOException {

        BufferedImage image = null;

        ImageInputStream is = ImageIO.createImageInputStream(new File(path));
        Iterator<ImageReader> iter = ImageIO.getImageReaders(is);
        ImageReader imageReader = (ImageReader) iter.next();
        imageReader.setInput(is);
        image = imageReader.read(0);

        return image;
    }
}

Related

  1. getBufferedImageAsType(int type, BufferedImage image, int sizeX, int sizeY)
  2. getBufferedImageBytes(BufferedImage bufferedImage)
  3. getBufferedImaged(Image img, int width, int height)
  4. getBufferedImageFrom3bytePixelArray(int[] rgb, int width, int height)
  5. getBufferedImageFromFile(String fileName)
  6. getBufferedImageMixedImages(BufferedImage image1, BufferedImage image2, int xImage2, int yImage2)
  7. getBufferedImageType(String encodeType)