Java Image Create getImage(Object obj, String filePath)

Here you can find the source of getImage(Object obj, String filePath)

Description

get Image

License

Apache License

Declaration

public static Image getImage(Object obj, String filePath) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.awt.*;

import javax.swing.*;
import java.net.URL;

public class Main {
    public static Image getImage(String fileName) {
        ImageIcon icon = getImageIcon(fileName);
        return (icon != null) ? icon.getImage() : null;
    }//from   ww  w .j  a v  a2  s . c  om

    public static Image getImage(URL url) {
        ImageIcon icon = getImageIcon(url);
        return (icon != null) ? icon.getImage() : null;
    }

    public static Image getImage(Object obj, String filePath) {
        URL url = obj.getClass().getResource(filePath);
        return getImage(url);
    }

    public static ImageIcon getImageIcon(String fileName) {
        URL url = ClassLoader.getSystemResource(fileName);
        return getImageIcon(url);
    }

    public static ImageIcon getImageIcon(URL url) {
        ImageIcon icon = (url == null) ? null : (new ImageIcon(url));
        return icon;
    }

    public static ImageIcon getImageIcon(Object obj, String filePath) {
        URL url = obj.getClass().getResource(filePath);
        return getImageIcon(url);
    }
}

Related

  1. getImage(File imageFile)
  2. getImage(final int width, final int height)
  3. getImage(final String name)
  4. getImage(ImageIcon imageIcon)
  5. getImage(JComponent component)
  6. makeImage(double[][] levels)
  7. makeImageResizer(String srcImgPath, String targerPath, int scaledWidth, int scaledHeight, boolean preserveAlpha)