Java BufferedImage Load loadImage(ClassLoader classLoader, String path)

Here you can find the source of loadImage(ClassLoader classLoader, String path)

Description

load Image

License

Open Source License

Declaration

public static BufferedImage loadImage(ClassLoader classLoader, String path) 

Method Source Code

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

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;

public class Main {
    public static BufferedImage loadImage(String path) {
        try {//from   w  w  w  .  j ava  2  s .  com
            URL url = ClassLoader.getSystemResource(path);
            if (url != null) {
                return ImageIO.read(url);
            } else {
                return null;
            }
        } catch (IOException e) {
            throw new RuntimeException("I/O error loading image " + path, e);
        }
    }

    public static BufferedImage loadImage(ClassLoader classLoader, String path) {
        try {
            URL url = classLoader.getResource(path);
            if (url != null) {
                return ImageIO.read(url);
            } else {
                return null;
            }
        } catch (IOException e) {
            throw new RuntimeException("I/O error loading image " + path, e);
        }
    }
}

Related

  1. loadFromResource(String imageName, Class cls)
  2. loadFromURL(String url)
  3. loadImage(byte[] data)
  4. loadImage(File file)
  5. loadImage(File file)
  6. loadImage(File file)
  7. loadImage(File file)