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

BufferedImageloadImage(final File imgFile)
can be overriden to load the image to use
if (imgFile != null && imgFile.exists()) {
    try {
        return ImageIO.read(imgFile);
    } catch (Exception e) {
return null;
BufferedImageloadImage(final File refDirectory, final String imageFileName)
load Image
final File imageFile = new File(refDirectory, imageFileName);
if (!imageFile.canRead()) {
    return null;
final BufferedImage image = ImageIO.read(imageFile);
return copyImage(image, newImage(image.getWidth(), image.getHeight()));
BufferedImageloadImage(final String fileName)
load Image
final File file = new File(fileName);
return file.isFile() ? loadImage(file) : null;
ImageloadImage(final String iconFile)
load Image
try {
    return ImageIO.read(
            ClassLoader.getSystemResourceAsStream("com/igormaznitsa/zxpspritecorrector/icons/" + iconFile));
} catch (Exception ex) {
    ex.printStackTrace();
return null;
java.awt.ImageloadImage(final String imagePathname, final Class relatedClass)
This is a utility method to help in loading icon images.
try {
    java.awt.image.ImageProducer ip = (java.awt.image.ImageProducer) java.security.AccessController
            .doPrivileged(new java.security.PrivilegedAction() {
                public Object run() {
                    java.net.URL url = relatedClass.getResource(imagePathname);
                    if (url == null)
                        return null;
                    try {
...
ImageloadImage(final String path)
This method loads an Image from the file system.
final ClassLoader loader = ClassLoader.getSystemClassLoader();
final URL fileLocation = loader.getResource(path);
final Image img = Toolkit.getDefaultToolkit().getImage(fileLocation);
if (img != null) {
    return img;
return Toolkit.getDefaultToolkit().getImage(fileLocation);
BufferedImageloadImage(final URL urlToImage)
Load image with URL.
try {
    return ImageIO.read(urlToImage);
} catch (IOException e) {
    System.err.print(urlToImage.toString() + " not found!");
    return null;
voidloadImage(Image image)
Loads the image, returning only when the image is loaded.
Component component = new Component() {
};
MediaTracker tracker = new MediaTracker(component);
synchronized (tracker) {
    int id = 0;
    tracker.addImage(image, id);
    try {
        tracker.waitForID(id, 0);
...
BufferedImageloadImage(InputStream inputStream)
load Image
BufferedImage image = ImageIO.read(inputStream);
return image;
BufferedImageloadImage(Object whoOrders, String name)
load Image
BufferedImage image = null;
try {
    image = ImageIO.read(whoOrders.getClass().getResource("/" + name));
} catch (IOException e) {
    e.printStackTrace();
return image;