Form in "Actual Size"

What a simple way to map a figure in Java to "actual size". For example, I have a tube with a diameter of 1 inch, and I want to display it on the screen as the outline of a 1 "circle. The Graphics2D drawOval (int x, int y, int width, int height) method takes the height and width in pixels. What are the steps to translate pixel size to the size displayed on the screen?

Thanks in advance.

+3
source share
8 answers

The getNormalizingTransform () method of the GraphicsConfiguration class looks as if it has potential

http://java.sun.com/javase/6/docs/api/java/awt/GraphicsConfiguration.html#getNormalizingTransform ()

+5
source

java.awt.Toolkit , . , .

, 1- , 1.0 * tk.getScreenResolution(), 2,5- 2.5 * tk.getScreenResolution() ..

+2

, , , - . , , , .

, , - , , .

+1

. Java.awt.Toolkit . , 1- , 1,0 * tk.getScreenResolution(), 2,5- 2,5 * tk.getScreenResolution() .. GraphicsConfiguration.getNormalizingTransform() "" .

, , ( ) . . . - , .

http://www.developer.com/java/other/print.php/626071 .

, , . , , .

, .

+1

, , - . , 100 × 100 17 "1280 x 1024 19" 1280 x 1024 .

, API, .

, .

, 1 , , .

0

, . , 17 " 1280: 1024.

- , . , /.

1280px ^ 2 + 1024px ^ 2 = c ^ 2, c ~ = 1639.2px. 1639.2px/17inch = 96.4px/inch 17- 1280x1024. .

0

, Toolkit . , -

float scalingFactor = Toolkit.getDefaultToolkit().getScreenResolution() / 72f;

1 "

int width = 1.0 * scalingFactor;

2,5 "

int width = 2.5 * scalingFactor;

, Java2D 72 dpi, ​​-, , .

0

, . , , (17 ", 21" ..), ("800x600, 1280x1024 ..) DPI (72, 96, 120 ..).

Through various api you can determine the screen resolution and, possibly, dpi ... but good luck with the screen size. And even so, you are still not guaranteed to get the right size on the screen.

-1
source

Source: https://habr.com/ru/post/1705752/


All Articles