我想要创造一个素描给出的图片;
是否可以为特定的屏幕大小和分辨率创建A4大小草图。如果是这样的话,我如何计算这个值。因为如您所知,处理使用size()方法进行处理,而大小的值是像素,而不是cm或mm。
因此,我想画8厘米的线,每当用户点击某一点的在线处理将显示距离的中心点(红点)的厘米。我可以用像素wise.However做这些事情,我不知道如何将这些值转换成厘米或毫米。
发布于 2014-02-17 23:02:01
此代码似乎工作正常(返回dpi):
import java.awt.Toolkit;
int resolution = Toolkit.getDefaultToolkit().getScreenResolution();
System.out.println(resolution);
然而,this answer认为这是不可靠的。如果您只想在单个监视器上运行它,那么可以手动计算它:
processing width = horizontal resolution(#pixels) / screen width(cm) * page width(cm)
processing height = vertical resolution(#pixels) / screen height(cm) * page height(cm)
编辑:这里有一个函数,用于将以厘米为单位的距离转换为像素的#:
int cmToPixels(float cm){
// this is a constant based on your screen's dimensions
// my monitor is 1366x768
int horizontalScreenResolution = 1366;
// this is the actual width of your screen in cm
int screenWidth = 32;
// NOTE: because pixels/cm should be the same vertically and horizontally,
// you could do the vertical equivalents for the above two constants.
return cm * horizontalScreenResolution / screenWidth;
}
我们的想法是把像素的总数除以它们所占的距离,给出每厘米的像素数。然后,你用你想要的线的厘米数乘以,它给你画线的像素。
https://stackoverflow.com/questions/21840588
复制相似问题