GDI+ 图片显示尺寸变大

这几天修改旧项目,在原来MFC封装框架之上添加PNG透明支持。使用GDI+中的 Image 和 Graphics 类的画图方法:

Status DrawImage(
  [in]  Image *image,
  [in]  INT x,
  [in]  INT y,
  [in]  INT srcx,
  [in]  INT srcy,
  [in]  INT srcwidth,
  [in]  INT srcheight,
  [in]  Unit srcUnit
);
发现画出的某些图片(具体是某些旧项目下面的BMP图片)比实际尺寸大,但是调用Image类方法GetWidth()和GetHeight()返回的尺寸是正确的。
 
解决方法如下:
调用其带有Rect参数类型的重载函数:
Status DrawImage(
  [in]       Image *image,
  [in, ref]  const Rect &destRect,
  [in]       INT srcx,
  [in]       INT srcy,
  [in]       INT srcwidth,
  [in]       INT srcheight,
  [in]       Unit srcUnit,
  [in]       ImageAttributes *imageAttributes,
  [in]       DrawImageAbort callback,
  [in]       VOID *callbackData
);
参考:

http://qsjming.blog.51cto.com/1159640/511838

http://blog.csdn.net/lanqiao825/article/details/5308808

http://msdn.microsoft.com/en-us/library/windows/desktop/ms536045(v=vs.85).aspx

是图片DPI的原因。

原文地址:https://www.cnblogs.com/aishangxue/p/3553268.html