3

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.

Philip
  • 58
  • 5

2 Answers2

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:

enter image description here

Using

Image image = createTestImage(64);

Produces a lo res image like:

enter image description here

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