将像素转换为cm

Jes*_*ssy 4 matlab pixel

如果我使用此公式的像素距离:

sqrt((x1-x2).^2+.(y1-y2)^2))
Run Code Online (Sandbox Code Playgroud)

我怎样才能把它转换成CM?

Dor*_*oom 7

调用'ScreenPixelsPerInch'属性:

dpix=sqrt((x1-x2)^2+(y1-y2)^2);          %# calculate distance in pixels
pixperinch=get(0,'ScreenPixelsPerInch'); %# find resolution of your display
dinch=dpix/pixperinch;                   %# convert to inches from pixels
dcm=dinch*2.54;                          %# convert to cm from inches
Run Code Online (Sandbox Code Playgroud)

或者对于单线方法:

dcm=sqrt((x1-x2)^2+(y1-y2)^2))/get(0,'ScreenPixelsPerInch')*2.54;
Run Code Online (Sandbox Code Playgroud)

编辑:您可能想检查您的系统是否获得屏幕大小和dpi正确.如果您知道显示器的尺寸和宽高比以及分辨率,则可以轻松完成.例如,我的设置:

宽屏16:9 23"显示器在1920x1080p

h^2+w^2=23^2 and h/w=9/16
Run Code Online (Sandbox Code Playgroud)

h=11.28 and w=20.05 inches
Run Code Online (Sandbox Code Playgroud)

get(0,'Screensize') 回报 [1 1 1920 1080]

get(0,'ScreenPixelsPerInch')返回96

所以1920/20.05 = 95.761080/11.28 = 95.74

也许我很幸运,但这种方法对我有用.

  • 我不知道matlab,但通常操作系统提供的屏幕DPI都是伪造的,即它们只是用来有一些线索来缩放文本(http://blogs.msdn.com/b/oldnewthing/存档/ 2004/07/14/182971.aspx?的PageIndex = 1).因此,使用该方法可能无法获得"真实"的屏幕尺寸. (2认同)