Java BufferedImage Load loadImage(final String path)

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

Description

This method loads an Image from the file system.

License

Apache License

Parameter

Parameter Description
path the path of the file to read

Return

the loaded image

Declaration

public static Image loadImage(final String path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2009, 2015, Danilo Pianini and contributors
 * listed in the project's build.gradle or pom.xml file.
 *
 * This file is distributed under the terms of the Apache License, version 2.0
 *******************************************************************************/

import java.awt.Image;
import java.awt.Toolkit;

import java.net.URL;

public class Main {
    /**//from  w  ww  .  j  a  v  a  2s  . c om
     * This method loads an Image from the file system.
     * 
     * @param path
     *            the path of the file to read
     * @return the loaded image
     */
    public static Image loadImage(final String path) {
        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);
    }
}

Related

  1. loadImage(final File imgFile)
  2. loadImage(final File refDirectory, final String imageFileName)
  3. loadImage(final String fileName)
  4. loadImage(final String iconFile)
  5. loadImage(final String imagePathname, final Class relatedClass)
  6. loadImage(final URL urlToImage)
  7. loadImage(Image image)
  8. loadImage(InputStream inputStream)
  9. loadImage(Object whoOrders, String name)