[英]Java JRE built-in image for testing purposes
Is there an image within the JRE that can be used for testing purposes? JRE中是否有可用于测试目的的图像? I'm looking for either an Image, BufferImage or Icon object.
我正在寻找一个Image,BufferImage或Icon对象。 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.
我确实在我正在使用的JRE路径中找到了一个PNG文件,但希望看到其他人找到或正在使用的内容。
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: 产生如下图像:
Depending on the OS, there are a number of image files bundled with the JRE... 根据操作系统的不同,JRE捆绑了许多图像文件......
There are images in C:\\Program Files\\Java\\jre7\\lib\\images\\cursors
on Windows, and on Linux I found: 在Windows上的
C:\\Program Files\\Java\\jre7\\lib\\images\\cursors
,在Linux上我发现:
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) ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.