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

BufferedImageloadImageFromFile(File file)
Loads a java.awt.image.BufferedImage from a java.io.File .
if (file == null)
    return null;
BufferedImage ret = null;
try {
    ret = ImageIO.read(file);
} catch (IOException e) {
    System.err.println("Could not load image from file! I/O Error!");
return ret;
ImageloadImageFromFile(String fileName)
load Image From File
try {
    return ImageIO.read(new File(fileName));
} catch (IOException e) {
    throw new RuntimeException(e);
ImageloadImageFromFile(String filename)
load Image From File
return ImageIO.read(new File(filename));
BufferedImageloadImageFromFile(String filepath)
Loads an image with the given file name.
return loadImageFromFile(new File(filepath));
ImageloadImageFromFile_ORIG(String imgName)
load Image From FilORIG
byte[] imageBytes = getBytesFromFile(imgName);
Image tmpi = null;
int numTries = 20;
if (imageBytes != null) {
    tmpi = Toolkit.getDefaultToolkit().createImage(imageBytes, 0, imageBytes.length);
    while (tmpi.getWidth(null) < 0 && numTries-- > 0) {
        try {
            Thread.sleep(100);
...
BufferedImageloadImagefromJar(Object refObj, String fileName)

This method loads a picture from a relative path string.

BufferedImage bi = null;
try {
    bi = ImageIO.read(refObj.getClass().getResourceAsStream(fileName));
} catch (IOException e) {
    e.printStackTrace();
return bi;
ImageloadImageFromURL(String imageURL, Component component)
Loads an image from a URL
if (imageURL == null) {
    return null;
Image result = null;
MediaTracker mediaTracker = new MediaTracker(component);
try {
    result = Toolkit.getDefaultToolkit().createImage(new URL(imageURL));
} catch (Exception ex) {
...
BufferedImageloadImageFromVisualgorithmJar(String imageFileName)
Loads the image indicated with imageFileName from the jar file of the application.
BufferedImage image = null;
try {
    image = ImageIO.read(urlClassLoader.findResource(imageFileName));
} catch (Exception ex) {
return image;
BufferedImageloadImageRessource(Object source, String file)
Load image ressource.
BufferedImage image = null;
try {
    image = ImageIO.read(source.getClass().getResource(file));
} catch (IOException ioe) {
    System.out.println(ioe.getMessage());
    try {
        image = ImageIO.read(source.getClass().getResource("src" + file));
    } catch (IOException e) {
...
voidloadImages(Image[] images, Component comp)
Load images (used for preloading images).
MediaTracker tracker = new MediaTracker(comp);
for (int i = 0; i < images.length; i++)
    tracker.addImage(images[i], 0);
try {
    tracker.waitForID(0);
} catch (InterruptedException ignore) {