Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JRE built-in image for testing purposes

Tags:

java

image

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.

like image 848
Philip Avatar asked Dec 28 '25 14:12

Philip


1 Answers

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

like image 138
Java42 Avatar answered Dec 31 '25 05:12

Java42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!