Java BufferedImage Load loadImage(String path)

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

Description

load Image

License

Open Source License

Declaration

public static Image loadImage(String path) 

Method Source Code


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

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;

public class Main {
    private static HashMap<String, Image> cache = new HashMap<String, Image>();

    public static Image loadImage(String path) {
        Image image = null;// w w  w  .  j a v a 2  s .co m

        if (cache.containsKey(path)) {
            return cache.get(path);
        }

        try {
            image = ImageIO.read(new File(path));

            if (!cache.containsKey(path)) {
                cache.put(path, image);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return image;
    }
}

Related

  1. loadImage(String filePath)
  2. loadImage(String i, int x, int imageWidth, int imageHeight)
  3. loadImage(String image)
  4. loadImage(String imageName)
  5. loadImage(String imageName, Component c)
  6. loadImage(String path)
  7. loadImage(String resourceName)
  8. loadImage(String url)
  9. loadImage(URL resource)