Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make java use millimeters instead of pixels?

My problem is that what I size a picture according to millimeters to pixels, and then print it out this will never be exact. My question is there a way to make java draw in millimeters or any other metric unit stead of pixels, because pixils will never be exact to millimeters.

like image 321
Maarten Avatar asked Feb 24 '26 00:02

Maarten


2 Answers

Get the screen DPI using java.awt.Toolkit.getDefaultToolkit().getScreenResolution(); Then simply do (MM * DPI)/25.4.
The outcome will be the amount of pixels relative to the physical length in MM.

like image 156
Maarten Avatar answered Feb 25 '26 13:02

Maarten


Doing some analysis, you could understand better:

pixels = mm * inch/mm * pixels/inch
pixels = mm (milimeters) * 25.4 (how many inches I have in 1 mm) * DPI (screen resolution)

DPI is dots per inch, which is the same of pixels per inch.

like image 29
Lucas Alves Avatar answered Feb 25 '26 12:02

Lucas Alves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!