public final class ImageResource extends Object
The images loaded this way are possibly "marked" or resized to take into account the display scaling.
The images loaded this way are all cached.
This class is thread-safe.
AWTUtil.getDisplayScaling()
,
IconResource
Modifier and Type | Method and Description |
---|---|
static void |
appendHTMLImg(Class<?> cls,
String name,
StringBuilder buffer)
Appends to specified buffer an <img> tag corresponding
to specified image resource.
|
static void |
appendHTMLImg(URL url,
StringBuilder buffer)
Appends to specified buffer an <img> tag corresponding
to specified image resource.
|
static BufferedImage |
colorizeImage(BufferedImage image,
Color foreground,
Color background)
Returns a copy of specified image colorized using specified colors.
|
static Image |
createDisabledImage(Image image)
Create a "disabled" (grayed) image corresponding to specified image.
|
static Image |
downscaleDoubleSizeImage(Image image)
Not part of the public API: downscale specified image
which is assumed to have been "marked" as being double size.
|
static void |
drawDoubleSizeImage(Graphics g,
Image image,
int x,
int y)
Not part of the public API: draw specified image
which is assumed to have been "marked" as being double size.
|
static void |
drawImage(Graphics g,
Image image,
int x,
int y)
Draw specified image.
|
static void |
drawPattern(Graphics g,
Image pattern,
int x0,
int y0,
int width,
int height)
Fills specified area width specified pattern.
|
static BufferedImage |
get(Class<?> cls,
String name)
Returns a ready to use image loaded from specified resource.
|
static BufferedImage |
get(Class<?> cls,
String name,
Color foreground,
Color background)
Returns a ready to use image loaded from specified image resource.
|
static BufferedImage |
get(URL url)
Returns a ready to use image loaded from specified URL.
|
static BufferedImage |
get(URL url,
Color foreground,
Color background)
Returns a ready to use image loaded from specified image URL.
|
static int |
getImageHeight(Image image)
Returns the height of specified image.
|
static int |
getImageWidth(Image image)
Returns the width of specified image.
|
static Image |
horizontalFlipImage(Image image)
Flip specified image horizontally.
|
static String |
insertAtX2(String location) |
static URL |
insertAtX2(URL url) |
static boolean |
isDoubleSizeImage(Image image)
Not part of the public API: tests wether specified image
has been "marked" as being double size.
|
public static BufferedImage get(Class<?> cls, String name)
cls
- used to specify which ClassLoader must be used to access the
image resourcename
- name of image resource (example "images/logo.png")null
if image resource is
not found or cannot be successfully loadedpublic static BufferedImage get(URL url)
url
- location of the imagepublic static BufferedImage get(Class<?> cls, String name, Color foreground, Color background)
A bitonal image may be colorized using specified colors.
cls
- the image resource belong to this classname
- filename of the image resource. Example: "myicon.png".foreground
- a new foreground color for the image.
null
means keep original foreground.background
- a new background color for the image.
null
means keep original background.public static BufferedImage get(URL url, Color foreground, Color background)
A bitonal image may be colorized using specified colors.
url
- location of the imageforeground
- a new foreground color for the image.
null
means keep original foreground.background
- a new background color for the image.
null
means keep original background.public static BufferedImage colorizeImage(BufferedImage image, Color foreground, Color background)
image
- image to be colorized.foreground
- a new foreground color for the image.
null
means keep original foreground.background
- a new background color for the image.
null
means keep original background.public static void appendHTMLImg(Class<?> cls, String name, StringBuilder buffer)
This utility is useful to create "rich" tooltips.
public static void appendHTMLImg(URL url, StringBuilder buffer)
This utility is useful to create "rich" tooltips.
public static int getImageWidth(Image image)
ImportantThis method must be used for all
the images loaded by ImageResource
.
public static int getImageHeight(Image image)
ImportantThis method must be used for all
the images loaded by ImageResource
.
public static void drawImage(Graphics g, Image image, int x, int y)
ImportantThis method must be used for all
the images loaded by ImageResource
.
public static boolean isDoubleSizeImage(Image image)
This happens only on a Retina Mac.
public static Image downscaleDoubleSizeImage(Image image)
This happens only on a Retina Mac.
public static void drawDoubleSizeImage(Graphics g, Image image, int x, int y)
This happens only on a Retina Mac.
public static void drawPattern(Graphics g, Image pattern, int x0, int y0, int width, int height)
g
- graphics object used to drawpattern
- fill patternx0
- X coordinate of the top/left of the area to be filledy0
- Y coordinate of the top/left of the area to be filledwidth
- width of the area to be filledheight
- height of the area to be filledpublic static Image createDisabledImage(Image image)
image
- an image