Here you can find the source of getBufferedImageFromPath(String path)
Parameter | Description |
---|---|
path | The path to the image |
Parameter | Description |
---|---|
IOException | If the file could not be read |
public static BufferedImage getBufferedImageFromPath(String path) throws IOException
//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; } }