下面列出了java.awt.image.MultiResolutionImage#getResolutionVariants() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void baseMultiResImageTest() {
int baseIndex = 1;
int length = 4;
BufferedImage[] resolutionVariants = new BufferedImage[length];
for (int i = 0; i < length; i++) {
resolutionVariants[i] = createImage(i);
}
MultiResolutionImage bmrImage = new BaseMultiResolutionImage(baseIndex, resolutionVariants);
List<Image> rvImageList = bmrImage.getResolutionVariants();
assertEquals("MultiResoltion Image shoudl contain the same number of resolution variants!", rvImageList.size(), length);
for (int i = 0; i < length; i++) {
int imageSize = getSize(i);
Image testRVImage = bmrImage.getResolutionVariant(imageSize, imageSize);
assertSame("Images should be the same", testRVImage, resolutionVariants[i]);
}
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
return;
}
String icon = "NSImage://NSApplicationIcon";
final Image image = Toolkit.getDefaultToolkit().getImage(icon);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Icon does not have resolution variants!");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
int width = 0;
int height = 0;
for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
int rvWidth = resolutionVariant.getWidth(null);
int rvHeight = resolutionVariant.getHeight(null);
if (rvWidth < width || rvHeight < height) {
throw new RuntimeException("Resolution variants are not sorted!");
}
width = rvWidth;
height = rvHeight;
}
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
return;
}
String icon = "NSImage://NSApplicationIcon";
final Image image = Toolkit.getDefaultToolkit().getImage(icon);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Icon does not have resolution variants!");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
int width = 0;
int height = 0;
for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
int rvWidth = resolutionVariant.getWidth(null);
int rvHeight = resolutionVariant.getHeight(null);
if (rvWidth < width || rvHeight < height) {
throw new RuntimeException("Resolution variants are not sorted!");
}
width = rvWidth;
height = rvHeight;
}
}
public void validateScreenCapture() throws AWTException {
Robot robot = new Robot();
outputControlPanel = new JPanel(layout);
GridBagConstraints ogbc = new GridBagConstraints();
MultiResolutionImage image
= robot.createMultiResolutionScreenCapture(inputImageFrame.getBounds());
List<Image> imageList = image.getResolutionVariants();
int size = imageList.size();
BufferedImage lowResImage = (BufferedImage) imageList.get(0);
BufferedImage highResImage = (BufferedImage) imageList.get(1);
outputImageFrame = new JFrame("Output");
outputImageFrame.getContentPane().setLayout(new GridBagLayout());
ogbc.gridx = 0;
ogbc.gridy = 0;
ogbc.fill = GridBagConstraints.HORIZONTAL;
outputControlPanel.add(new JLabel(new ImageIcon(lowResImage)), ogbc);
int width = lowResImage.getWidth();
int height = lowResImage.getHeight();
JLabel labelImg1 = new JLabel("LEFT:Width: " + width
+ " Height: " + height);
ogbc.gridx = 0;
ogbc.gridy = 1;
outputControlPanel.add(labelImg1, ogbc);
ogbc.gridx = 1;
ogbc.gridy = 0;
outputControlPanel.add(new JLabel(new ImageIcon(highResImage)), ogbc);
width = highResImage.getWidth();
height = highResImage.getHeight();
JLabel labelImg2 = new JLabel("RIGHT:Width: " + width
+ " Height: " + height);
ogbc.gridx = 1;
ogbc.gridy = 1;
outputControlPanel.add(labelImg2, ogbc);
outputControlPanel.setBackground(Color.GRAY);
outputImageFrame.add(outputControlPanel);
outputImageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
outputImageFrame.setBounds(600, 0, 400, 300);
outputImageFrame.setLocationRelativeTo(null);
outputImageFrame.setVisible(true);
}