JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
ManualHiDPIBufferedImage01AWT.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.awt;
2
3import java.awt.BorderLayout;
4import java.awt.Canvas;
5import java.awt.Dimension;
6import java.awt.Graphics;
7import java.awt.Graphics2D;
8import java.awt.Image;
9import java.awt.image.BufferedImage;
10import java.lang.reflect.InvocationTargetException;
11
12import javax.swing.JCheckBox;
13import javax.swing.JComponent;
14import javax.swing.JFrame;
15import javax.swing.SwingUtilities;
16
17/**
18 * Manual test for BufferedImage behavior w/ OSX HiDPI pixel scale usage.
19 */
21
22 static final int width = 200;
23 static final int height = 100;
24
25 public static void main(final String[] args) throws InterruptedException, InvocationTargetException {
26 final JFrame frame = new JFrame();
27
28 SwingUtilities.invokeLater(new Runnable() {
29 @Override
30 public void run() {
31 final Image image1 = getImage(getCheckBox("High-DPI (no)", false), width, height, 1);
32 final Image image2 = getImage(getCheckBox("High-DPI (yes)", true), width, height, 2);
33 System.err.println("Image1: "+image1);
34 System.err.println("Image2: "+image2);
35
36 @SuppressWarnings("serial")
37 final Canvas canvas = new Canvas() {
38 @Override
39 public void paint(final Graphics g) {
40 super.paint(g);
41 g.drawImage(image1, 0, 0, width, height, this);
42 g.drawImage(image2, 0, height + 5, width, height, this);
43 }
44 };
45 frame.getContentPane().add(getCheckBox("High-DPI (ref)", false), BorderLayout.NORTH);
46 frame.getContentPane().add(canvas, BorderLayout.CENTER);
47
48 frame.setBounds((1440-400)/2, 100, 400, 400);
49 frame.validate();
50 frame.setVisible(true);
51 }
52 });
53 }
54
55 static JCheckBox getCheckBox(final String text, final boolean selected) {
56 final JCheckBox checkBox = new JCheckBox(text);
57 checkBox.setSelected(selected);
58 checkBox.setSize(new Dimension(width, height));
59 return checkBox;
60 }
61
62 static Image getImage(final JComponent component, final int width, final int height, final int scale) {
63 final BufferedImage image = new BufferedImage(width*scale, height*scale, BufferedImage.TYPE_INT_ARGB);
64 final Graphics g = image.getGraphics();
65 ((Graphics2D) g).scale(scale, scale);
66 component.paint(g);
67 g.dispose();
68
69 return image;
70 }
71}
Manual test for BufferedImage behavior w/ OSX HiDPI pixel scale usage.