Is there an image within the JRE that can be used for testing purposes? I'm looking for either an Image, BufferImage or Icon object. I did find a PNG file in the JRE path that I am currently using but looking to see what others have found or are using.
Asked
Active
Viewed 395 times
3
-
1why do you need an image "within JRE" ? – Raptor Mar 13 '13 at 04:21
-
So I don't have to rely on reading a PNG or JPG file from the file system. I'm looking for a built-in image. Trying to see if others have discovered such an object. – Philip Mar 13 '13 at 04:24
-
1how about create one using Java? – Raptor Mar 13 '13 at 04:27
-
1There are a number of icons in the JRE for the PLAFs. E.G. as seen [here](http://stackoverflow.com/a/7877817/418556). A new `BufferedImage` is as simple as `new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);` – Andrew Thompson Mar 13 '13 at 04:31
-
@ShivanRaptor I currently do create one using Java from a PNG file in the JRE path. I'm looking to see what others have found or are using. – Philip Mar 13 '13 at 04:32
-
@AndrewThompson - Locations or Names? – Philip Mar 13 '13 at 04:33
-
@AndrewThompson - Thanks...looking for those now. – Philip Mar 13 '13 at 04:36
2 Answers
2
Try the following. This code will generate a test image of any resolution. It does not use a built-in image but I think this will work best for you. Tweak as necessary to meet your needs.
static private Image createTestImage(final int resolution) {
final Image image = new BufferedImage(resolution, resolution, BufferedImage.TYPE_INT_ARGB);
final Graphics g = image.getGraphics();
final int points = (resolution * 72) / 96;
g.setColor(new Color(.42f, .42f, 1.0f, .5242f));
g.setFont(new Font("Dialog", Font.BOLD, points));
g.drawString("!X!", 2, points);
g.setColor(Color.BLACK);
g.drawOval(0, 0, image.getWidth(null) - 1, image.getHeight(null) - 1);
g.drawOval(11, 11, image.getWidth(null) - 23, image.getHeight(null) - 23);
g.drawOval(22, 22, image.getWidth(null) - 45, image.getHeight(null) - 45);
return image;
}
Using
Image image = createTestImage(1024);
Produces a hi res image like:
Using
Image image = createTestImage(64);
Produces a lo res image like:

Java42
- 7,628
- 1
- 32
- 50
0
Depending on the OS, there are a number of image files bundled with the JRE...
There are images in C:\Program Files\Java\jre7\lib\images\cursors
on Windows, and on Linux I found:
denis@laptop:~/Programs/jdk1.7.0_11/jre$ find | grep png
./lib/deploy/mixcode_s.png
./lib/images/icons/sun-java.png
./lib/images/icons/sun-java_HighContrast.png
./lib/images/icons/sun-java_HighContrastInverse.png
./lib/images/icons/sun-java_LowContrast.png
... (many others) ...

Denis Fuenzalida
- 3,271
- 1
- 17
- 22