Java Utililty Methods BufferedImage Load

List of utility methods to do BufferedImage Load

Description

The list of methods to do BufferedImage Load are organized into topic(s).

Method

ImageloadFromResource(String imageName, Class cls)
Loads an Image named imageName as a resource relative to the Class cls.
try {
    final URL url = cls.getResource(imageName);
    if (url == null) {
        return null;
    Image image = (Image) imageCache.get(url.toString());
    if (image == null) {
        image = Toolkit.getDefaultToolkit().createImage(url);
...
BufferedImageloadFromURL(String url)
load From URL
try {
    return ImageIO.read(new URL(url));
} catch (IOException e) {
    e.printStackTrace();
return null;
BufferedImageloadImage(byte[] data)
load Image
BufferedImage img = null;
try (InputStream input = new ByteArrayInputStream(data)) {
    img = ImageIO.read(input);
return img;
BufferedImageloadImage(ClassLoader classLoader, String path)
load Image
try {
    URL url = classLoader.getResource(path);
    if (url != null) {
        return ImageIO.read(url);
    } else {
        return null;
} catch (IOException e) {
...
BufferedImageloadImage(File file)
Load an image from a file using ImageIO.
ImageInputStream is = ImageIO.createImageInputStream(file);
Iterator<ImageReader> iter = ImageIO.getImageReaders(is);
if (!iter.hasNext()) {
    throw new IOException("Unsupported file format.");
ImageReader imageReader = iter.next();
imageReader.setInput(is);
return imageReader.read(0);
...
BufferedImageloadImage(File file)
Loads image from the file.
try {
    return ImageIO.read(file);
} catch (IOException ex) {
    throw new RuntimeException("IOException whle trying to load image file" + file.getName(), ex);
BufferedImageloadImage(File file)
load Image
final FileInputStream fis = new FileInputStream(file);
try {
    final BufferedImage bufferedImage = ImageIO.read(fis);
    if (bufferedImage == null) {
        throw new IOException("ImageIO.read returned null for " + file);
    return bufferedImage;
} finally {
...
BufferedImageloadImage(File file)
load Image
BufferedImage bi = null;
try {
    bi = ImageIO.read(file);
} catch (IOException e) {
    e.printStackTrace();
return bi;
BufferedImageloadImage(File pFile)
load Image
BufferedImage im = ImageIO.read(pFile);
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
GraphicsConfiguration config = device.getDefaultConfiguration();
BufferedImage buffy = config.createCompatibleImage(im.getWidth(), im.getHeight(), im.getTransparency());
Graphics2D g2d = buffy.createGraphics();
setupGraphics(g2d);
g2d.drawImage(im, 0, 0, null);
...
BufferedImageloadImage(final byte[] imageData)
Uses javax.imageio.ImageIO to read the specified data into a java.awt.image.BuffededImage.
final ByteArrayInputStream in = new ByteArrayInputStream(imageData);
final BufferedImage bi = ImageIO.read(in);
in.close();
return bi;