[英]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.
我的问题是有一种方法可以使java以毫米或任何其他公制单位代替像素,因为像素数永远不会精确到毫米。
Get the screen DPI
using java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
使用
java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
获取屏幕DPI
java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
Then simply do (MM * DPI)/25.4
. 然后只需做
(MM * DPI)/25.4
。
The outcome will be the amount of pixels relative to the physical length in MM. 结果将是相对于MM物理长度的像素数量。
If you know the resolution - px/cm you can do the calculation in centimeters I guess. 如果您知道分辨率-px / cm,我可以以厘米为单位进行计算。 However, printers and displays have different resolutions based on the hardware itself.
但是,打印机和显示器根据硬件本身具有不同的分辨率。 In Photoshop for example you can define how many pixels per inch you desire.
例如,在Photoshop中,您可以定义所需的每英寸像素数。 Whether a printer can actually print the defined density depends on the printer itself.
打印机是否可以实际打印定义的浓度取决于打印机本身。
As an extreme example think about a 46 inch television and your smart phone. 举一个极端的例子,考虑一下46英寸电视和您的智能手机。 Both claim 1080 hd images but clearly the size in inches is drastically different.
两者都要求提供1080个高清图像,但显然以英寸为单位的尺寸却大不相同。
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. DPI是每英寸点数,每英寸像素数相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.