Here you can find the source of getImageFromClassResource(Class> cls, String resource)
Parameter | Description |
---|---|
cls | The class. |
resource | Path of the resource, i.e. "images/main.gif", relative to the class. |
public static Image getImageFromClassResource(Class<?> cls, String resource)
//package com.java2s; //License from project: Open Source License import java.awt.Image; import javax.swing.ImageIcon; public class Main { /**/*from w w w . j a va2s . co m*/ * Get an Image from a resource in a class. * * @param cls The class. * @param resource Path of the resource, i.e. "images/main.gif", relative to * the class. * @return */ public static Image getImageFromClassResource(Class<?> cls, String resource) { if (cls == null || resource == null) return null; java.net.URL imgURL = cls.getResource(resource); if (imgURL != null) { return new ImageIcon(imgURL).getImage(); } else { return null; } } }