如何将GDI位图转换为GDI +位图,DrawImage?

问题描述

我正在将C ++ pgm从GDI转换为GDI +,以便利用GDI +中的一些新功能。但是我遇到了一个奇怪的问题:GDI +绘制的图像看起来大了约1.3倍,并且在屏幕上的位置略有不同。

这是GDI中的代码,它可以按预期工作-将矩形从位图复制到屏幕,其大小与原始位图中的大小相同。我想知道如何让GDI +做完全一样的事情。

HDC hdc = GetDC(hWnd);
HANDLE hDcmem = CreateCompatibleDC(hdc);
HANDLE hBitmap = LoadImage(NULL,L"C:\\MyBitmap.bmp",IMAGE_BITMAP,LR_LOADFROMFILE);
HANDLE hSelect = SelectObject(hDcmem,hBitmap);

// In OnPaint:
// pt is the destination,in screen pixels  px,py are the position in the source bitmap  w and h are the size of the source and destination rectangles
DWORD rop = SRCcopY;
bool ok = BitBlt(hdc,pt.x,pt.y,w,h,hDcmem,px,py,rop);

这是我希望做同样的事情的GDI +中的代码,但事实并非如此。即使DrawImage的参数与GDI的BitBlt的参数相同,我也会得到不同的结果。

GdiplusstartupInput gdiplusstartupInput;
Status gdistatus=Gdiplusstartup(&GDIPlusToken,&gdiplusstartupInput,NULL); // GDI+ version is 1

// Get the bitmap
Bitmap *tBitmap;
tBitmap = new Bitmap(L"C:\\MyBitmap.bmp");
Status st = tilesBitmap->GetLastStatus(); // ok

// display part of the image
In OnPaint:
Graphics graphics(hdc);
// pt is the destination,py are the position in the source bitmap  w and h are the size of the source and destination rectangles
Status st = graphics.DrawImage(tBitmap,(int)pt.x,(int)pt.y,UnitPixel);

如果将UnitPixel更改为Unitdisplay,则会从DrawImage收到无效的参数错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)