如何知道每厘米对应多少象素?

streamIF 2005-10-16 11:11:11
如题。
当用户改变显示分辨率时,每厘米对应的象素值都不同,我应当如何计算出当前显示器上每厘米对应多少个象素?(不同的显示器,甚至是打印机用这个象素值,作为尺寸单位是否精确?)
...全文
141 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinhuiming 2005-10-18
  • 打赏
  • 举报
回复
我在做比例尺的时候是这样做的:
pDC->GetDeviceCaps(HORZRES)/pDC->GetDeviceCaps(HORZSIZE)
streamIF 2005-10-16
  • 打赏
  • 举报
回复
为什么我的显示器上每英寸是96个象素,无论分辨率是1024*768还是640*480。而有的显示器上是每英寸是72个象素?

如果打印机上每英寸是180个象素,我的显示器上每英寸是96个象素,那我在显示器上的一英寸通过打印机打印出来会是一英寸吗?如何处理来保证打印出来的也是一英寸?
菜牛 2005-10-16
  • 打赏
  • 举报
回复
GetDeviceCaps
vcmute 2005-10-16
  • 打赏
  • 举报
回复
INFO: Calculating The Logical Height and Point Size of a Font

Q74299


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Windows Software Development Kit (SDK) 3.1
Microsoft Win32 Application Programming Interface (API), used with:
Microsoft Windows NT Server versions 3.5, 3.51, 4.0
Microsoft Windows NT Workstation versions 3.5, 3.51, 4.0

--------------------------------------------------------------------------------


SUMMARY
To create a font in the Microsoft Windows graphical environment given only the required point size, an application must calculate the logical height of the font because the CreateFont() and CreateFontIndirect() functions use logical units to specify height.

To describe a font to the user, an application can calculate a font's point size, given its height. This article provides the formulas required to perform these calculations for the MM_TEXT mapping mode. You will have to derive a new equation to calculate the font size in another mapping mode.



MORE INFORMATION
To calculate the logical height, use the following formula:


Point Size * LOGPIXELSY
height = Internal Leading + -------------------------
72
LOGPIXELSY is the number of pixels contained in a logical inch on the device. This value is obtained by calling the GetDeviceCaps() function with the LOGPIXELSY index. The value 72 is significant because one inch contains 72 points.

The problem with this calculation is that there is no method to determine the internal leading for the font because it has not yet been created. To work around this difficulty, use the following variation of the formula:

-(Point Size * LOGPIXELSY)
height = --------------------------
72
This formula may also be written as follows:

plf->lfHeight = -MulDiv (nPtSize, GetDeviceCaps (hdc, LOGPIXELSY), 72);
When an application calls the CreateFont() or CreateFontIndirect() functions and specifies a negative value for the height parameter, the font mapper provides the closest match for the character height rather than the cell height. The difference between the cell height and the character height is the internal leading, as demonstrated by the following diagram:

---------- <------------------------------
| | |- Internal Leading |
| | | | <--------- |
| | | | | |- Cell Height
| |---| | |- Character Height |
| | | | | |
| | | | | |
---------- <------------------------------
The following formula computes the point size of a font:

(Height - Internal Leading) * 72
Point Size = --------------------------------
LOGPIXELSY
The Height and Internal Leading values are obtained from the TEXTMETRIC data structure. The LOGPIXELSY value is obtained from the GetDeviceCaps function as outlined above.

Round the calculated point size to the nearest integer. The Windows MulDiv() function rounds its result and is an excellent choice to perform the previous calculation.
ggw 2005-10-16
  • 打赏
  • 举报
回复
这东西自己计算?设置时已定了吧。用GetDeviceCaps读出象素和厘米表示的值除一下?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧