用于测试目的的Java JRE内置映像 [英] Java JRE built-in image for testing purposes

查看:50
本文介绍了用于测试目的的Java JRE内置映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JRE中是否有可用于测试目的的图像?我在寻找一个Image,BufferImage或Icon对象.我确实在我当前正在使用的JRE路径中找到了一个PNG文件,但希望查看其他人已发现或正在使用的文件.

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.

推荐答案

请尝试以下操作.此代码将生成任何分辨率的测试图像.它不使用内置图像,但我认为这将最适合您.根据需要进行调整以满足您的需求.

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;
}

使用

Image image = createTestImage(1024);

产生高分辨率图像,例如:

Produces a hi res image like:

使用

Image image = createTestImage(64);

产生像这样的低分辨率图像:

Produces a lo res image like:

这篇关于用于测试目的的Java JRE内置映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆