Java Image Create getImage(final String name)

Here you can find the source of getImage(final String name)

Description

get Image

License

Apache License

Declaration

public static Image getImage(final String name) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static Map<String, ImageIcon> images = new HashMap<>();

    public static Image getImage(final String name) {
        final ImageIcon icon = images.get(name);
        if (icon == null) {
            try {
                final ImageIcon image = new ImageIcon(
                        ImageIO.read(new File(name)));
                images.put(name, image);
                return image.getImage();
            } catch (Exception e) {
                return null;
            }/*from  w w  w . j ava2  s  .co  m*/
        }
        return icon.getImage();
    }
}

Related

  1. getImage(Class clazz, String path)
  2. getImage(Component component)
  3. getImage(Component component)
  4. getImage(File imageFile)
  5. getImage(final int width, final int height)
  6. getImage(ImageIcon imageIcon)
  7. getImage(JComponent component)
  8. getImage(Object obj, String filePath)
  9. makeImage(double[][] levels)