Java Code Examples for java.awt.image.MultiResolutionImage#getResolutionVariants()

The following examples show how to use java.awt.image.MultiResolutionImage#getResolutionVariants() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiResultionImageUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@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]);
    }

}
 
Example 2
Source File: NSImageToMultiResolutionImageTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    }
 
Example 3
Source File: NSImageToMultiResolutionImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    }
 
Example 4
Source File: ScreenCaptureResolutionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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);
}