GDI映射模式杂谈

最近一直在烦恼,到底怎样,怎样获取物理尺寸、物理像素之间的对应关系呢?

最常见的莫过于以下的写法:

	// 计算一个设备单位等于多少0.1mm
	double scaleX = 254.0 / (double)GetDeviceCaps(dc.m_hAttribDC,LOGPIXELSX); // 2048X1152 96DPI
	double scaleY = 254.0 / (double)GetDeviceCaps(dc.m_hAttribDC, LOGPIXELSY); // 2048X1152 96DPI

 我自己是这样写的:

	double mmScreenX = (double)::GetDeviceCaps(dc.m_hAttribDC, HORZSIZE); // 722mm
	double nMMPixelX = (double)::GetDeviceCaps(dc.m_hAttribDC, HORZRES)/mmScreenX;
	double mmScreenY = (double)::GetDeviceCaps(dc.m_hAttribDC, VERTSIZE); // 406mm
	double nMMPixelY = (double)::GetDeviceCaps(dc.m_hAttribDC, VERTRES)/mmScreenY;

用VS2010调试的结果:

scaleX = scaleY = 2.6458333333333335  // 每像素对应多少0.1mm
nMMPixelX = 2.8365650969529086 // 每毫米对应多少像素
nMMPixelY = 2.8374384236453203 // 每毫米对应多少像素

哎,254.0那个写法是最流行的,但最流行的问题:为什么HORZSIZE的实际值不等于25.4*HORZRES/LOGPIXELSX?

有个兄弟说的特别清楚,这些东西不是绝对的正确,依赖系统字体、Windows版本,我其实被微软这些操蛋的东西搞晕了,写这里继续操蛋,哎。

记住:LOGPIXELSX的值一般是固定的(96DPI,120DPI,听说和字体有关),另外两个成比例同时放大缩小。

关于GDI不想再说了,过时的东西,现在流行的不再是逻辑坐标、视口坐标、设备坐标如何转换了。看看GDI+,现在流行的是Matrix:矩阵革命(黑客帝国啊)。

有了Matrix那可是利器啊,你想干啥,就使用Matrix吧。放大、缩小、平移、反转、扭曲,一切都变得简单。熟悉Android的都知道Matrix的强大,可以save,然后resotre。当然这里也可以。

譬如,你坐标系是Y轴是反的,标注是正的。http://www.bobpowell.net/ReverseAxisText.htm

摘录一段老外写的:http://www.bobpowell.net/mappingmodes.aspx

GDI+ has three distinct graphical spaces. They are the World, Page and Device spaces. The world space corresponds to the GDI logical space but with one important difference, the coordinate system is based on floating point rather than integer units. This means that real-world measurements can be catered for without the potential for overflowing the logical coordinate space. You can for example specify a measurement of 1.75 inches or 300,000.5 millimeters. The Page space controls the relationship between the abstract world space and the Device space and ensures that pixels placed an inch apart in the world space appear an inch apart on any and all devices. You can specify that the page units are measured in inches, millimeters, pixels and points which are all real-world measurements and an additional couple of pseudo real-world standards called Device and Display which are 1/300th of an inch and 1/75th of an inch respectively.When a pixel is plotted in the world space, it is automatically transformed by the page space to the device space and displayed in the correct position on screen. This type of bucket-brigade calculation system is called a pipeline and may have other steps inserted into the chain to further modify the appearance of the image rendered on the display. The important one from the point of view of this discussion is the current graphics transform which is stored in a Matrix which is a property of the Graphics object used to do drawing in GDI+.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

欣爸爸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值