象素转为毫米单位

时间:2022-02-19 20:05:53
1 请高手提供一下精确计算一个象素是多少毫米的方法。
2 另外,我如何获得显示器的大小以及分辨率呢?
急盼高手指点!!!!!!!!!!!!!!!!!!!!!!!!!!!!

10 个解决方案

#1


2 可以参考一下CDC的函数,里面都有介绍!msdn,或类库参考的书里面都有介绍!

#2


第一个问题
像素不是系统给你定了多少毫米的
系统得到的只是你显示器的分辨率,如1024*768,860*480
所以你要换算成毫米,只能你自己在程序里头定义pixelweight=多少

第二个问题
x = GetSystemMetrics(SM_CXSCREEN); 
y = GetSystemMetrics(SM_CYSCREEN); 
ShowMessage("显示器水平分辨率:" + AnsiString(x) + "\n\n显示器垂直分辨率:" + AnsiString(y)); 

#3


GetDeviceCaps
HORZSIZE Width, in millimeters, of the physical screen. 
VERTSIZE Height, in millimeters, of the physical screen. 
或是先獲得每一英寸所對應的pixel數.再將英寸轉為毫米.
LOGPIXELSX  Number of pixels per logical inch along the screen width. In a system with multiple display monitors, this value is the same for all monitors. 
LOGPIXELSY  Number of pixels per logical inch along the screen height. In a system with multiple display monitors, this value is the same for all monitors. 

#4


设一下映射方式就行了呗,SetMapMode(MM_LOMETRIC),以0.1毫米为单位

#5


可以在你的程序的任何地方:
int x = GetSystemMetrics(SM_CXSCREEN);
int y = GetSystemMetrics(SM_CYSCREEN);
CString ClrText;
ClrText.Format("水平分辨率:%d\n垂直分辨率:%d",x,y);
::MessageBox(NULL,ClrText,"输出的RGB值",MB_OK);

#6


第一个问题:
严重同意WQS6

#7


谢谢各位,我在绘图时使用pDC->SetMapMode(MM_HIMETRIC);
然后开始打印预览,需要重新计算一下放大率:
我先取屏幕窗口
CRect clientrect;
GetClientRect(clientrect);
这时clientrect为{top=0,bottom=739,left=0,right=1014}
因为我想把这个矩形的长度和宽度转换为毫米单位,所以请教大家怎样计算一个象素是多少毫米,请高手提供一个计算方法(屏幕分辨率1024×768),谢谢!

to COOL099(Alan Zjou):我也想获得每英寸对应的 pixel数,可怎么获得呢?

盼望您不吝赐教!!!!!!!!急呀。

#8


double pLogHeighty=(double)pDC->GetDeviceCaps(LOGPIXELSY);
double pLogHeightx=(double)pDC->GetDeviceCaps(LOGPIXELSX);

mPageHeight=(int)((mPhysicalHeight/pLogHeighty)*25.4+0.5);
mPageWidth =(int)((mPhysicalWidth/pLogHeightx)*25.4+0.5);

#9


也好像是这个,忘了哪个了
dc.LineTo(0,(g_iCustomClipHeight-1)*::GetDeviceCaps(hDC,LOGPIXELSY)/25.4);

#10


再次感谢,可能我问的不清楚,其实我就是想求出clientrect的实际宽度高度(例如用毫米作单位)

#1


2 可以参考一下CDC的函数,里面都有介绍!msdn,或类库参考的书里面都有介绍!

#2


第一个问题
像素不是系统给你定了多少毫米的
系统得到的只是你显示器的分辨率,如1024*768,860*480
所以你要换算成毫米,只能你自己在程序里头定义pixelweight=多少

第二个问题
x = GetSystemMetrics(SM_CXSCREEN); 
y = GetSystemMetrics(SM_CYSCREEN); 
ShowMessage("显示器水平分辨率:" + AnsiString(x) + "\n\n显示器垂直分辨率:" + AnsiString(y)); 

#3


GetDeviceCaps
HORZSIZE Width, in millimeters, of the physical screen. 
VERTSIZE Height, in millimeters, of the physical screen. 
或是先獲得每一英寸所對應的pixel數.再將英寸轉為毫米.
LOGPIXELSX  Number of pixels per logical inch along the screen width. In a system with multiple display monitors, this value is the same for all monitors. 
LOGPIXELSY  Number of pixels per logical inch along the screen height. In a system with multiple display monitors, this value is the same for all monitors. 

#4


设一下映射方式就行了呗,SetMapMode(MM_LOMETRIC),以0.1毫米为单位

#5


可以在你的程序的任何地方:
int x = GetSystemMetrics(SM_CXSCREEN);
int y = GetSystemMetrics(SM_CYSCREEN);
CString ClrText;
ClrText.Format("水平分辨率:%d\n垂直分辨率:%d",x,y);
::MessageBox(NULL,ClrText,"输出的RGB值",MB_OK);

#6


第一个问题:
严重同意WQS6

#7


谢谢各位,我在绘图时使用pDC->SetMapMode(MM_HIMETRIC);
然后开始打印预览,需要重新计算一下放大率:
我先取屏幕窗口
CRect clientrect;
GetClientRect(clientrect);
这时clientrect为{top=0,bottom=739,left=0,right=1014}
因为我想把这个矩形的长度和宽度转换为毫米单位,所以请教大家怎样计算一个象素是多少毫米,请高手提供一个计算方法(屏幕分辨率1024×768),谢谢!

to COOL099(Alan Zjou):我也想获得每英寸对应的 pixel数,可怎么获得呢?

盼望您不吝赐教!!!!!!!!急呀。

#8


double pLogHeighty=(double)pDC->GetDeviceCaps(LOGPIXELSY);
double pLogHeightx=(double)pDC->GetDeviceCaps(LOGPIXELSX);

mPageHeight=(int)((mPhysicalHeight/pLogHeighty)*25.4+0.5);
mPageWidth =(int)((mPhysicalWidth/pLogHeightx)*25.4+0.5);

#9


也好像是这个,忘了哪个了
dc.LineTo(0,(g_iCustomClipHeight-1)*::GetDeviceCaps(hDC,LOGPIXELSY)/25.4);

#10


再次感谢,可能我问的不清楚,其实我就是想求出clientrect的实际宽度高度(例如用毫米作单位)