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

ImageloadImage(String path)
load Image
URL imgUrl = ClassLoader.getSystemResource(path);
Image img = Toolkit.getDefaultToolkit().getImage(imgUrl);
return img;
ImageloadImage(String path)
load Image
Image image = null;
if (cache.containsKey(path)) {
    return cache.get(path);
try {
    image = ImageIO.read(new File(path));
    if (!cache.containsKey(path)) {
        cache.put(path, image);
...
ImageloadImage(String resourceName)
Loads an image from a resource.
if (PREFER_TOOLKIT) {
    return Toolkit.getDefaultToolkit().createImage(ClassLoader.getSystemResource(resourceName));
} else {
    try (InputStream input = ClassLoader.getSystemResourceAsStream(resourceName)) {
        return (input == null) ? null : ImageIO.read(input);
ImageloadImage(String url)
load Image
InputStream stream = ClassLoader.getSystemClassLoader().getResourceAsStream(url);
Image image = ImageIO.read(stream);
return image;
BufferedImageloadImage(URL resource)
load Image
BufferedImage image = null;
try {
    image = ImageIO.read(resource);
} catch (IOException e) {
return image;
ImageloadImage(URL url)
Load an image from a given URL.
MediaTracker tracker = new MediaTracker(new java.awt.Container());
Image img = java.awt.Toolkit.getDefaultToolkit().createImage(url);
tracker.addImage(img, 0);
tracker.waitForAll();
return img;
int[]loadImageData(BufferedImage image)
load Image Data
int w = image.getWidth();
int h = image.getHeight();
int[] pixels = image.getRGB(0, 0, w, h, null, 0, w);
return pixels;
double[]loadImageData(String name)
load Image Data
BufferedImage bi = null;
double[] arr = null;
try {
    File f = new File(name);
    bi = ImageIO.read(f);
    int w = bi.getWidth(null);
    int h = bi.getHeight(null);
    arr = new double[w * h];
...
ImageloadImageFromBytes(byte[] bytes)
load Image From Bytes
try {
    ByteArrayInputStream is = new ByteArrayInputStream(bytes);
    BufferedImage image = ImageIO.read(is);
    is.close();
    return image;
} catch (IOException e) {
    throw new RuntimeException(e);
ImageloadImageFromFile(File f)
load Image From File
try {
    return ImageIO.read(f);
} catch (IOException e) {
    System.out.println("Couldn't load image " + f.getPath());
    e.printStackTrace();
return null;