如何将GDI位图转换为GDI+;位图,绘图图像? 我将C++ PGM从GDI转换为GDI+,以利用GDI+中的一些新特性。但我遇到了一个奇怪的问题:GDI+绘制的图像看起来大了约1.3倍,并且在屏幕上的位置略有不同
这是GDI中的代码,它按预期工作——它将一个矩形从位图复制到屏幕上,大小与原始位图中的相同。我想知道如何让GDI+做完全相同的事情如何将GDI位图转换为GDI+;位图,绘图图像? 我将C++ PGM从GDI转换为GDI+,以利用GDI+中的一些新特性。但我遇到了一个奇怪的问题:GDI+绘制的图像看起来大了约1.3倍,并且在屏幕上的位置略有不同,c++,bitmap,gdi+,gdi,C++,Bitmap,Gdi+,Gdi,这是GDI中的代码,它按预期工作——它将一个矩形从位图复制到屏幕上,大小与原始位图中的相同。我想知道如何让GDI+做完全相同的事情 HDC hdc = GetDC(hWnd); HANDLE hDCMem = CreateCompatibleDC(hdc); HANDLE hBitmap = LoadImage(NULL, L"C:\\MyBitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); HANDLE hSelect = S
HDC hdc = GetDC(hWnd);
HANDLE hDCMem = CreateCompatibleDC(hdc);
HANDLE hBitmap = LoadImage(NULL, L"C:\\MyBitmap.bmp", IMAGE_BITMAP, 0, 0, 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, in screen pixels px,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, px, py, w, h, UnitPixel);
如果我将
UnitPixel
更改为UnitDisplay
,我会从DrawImage
中得到一个无效的参数错误,该Q的所有注释都已消失。总之,合成模式已经是CompositingModeSourceOver
,通过“参数相同”,我指的是位置和大小。由于GDI+大小是x和y中GDI大小的4/3,因此可能是位图不兼容。GDI+位图是ImageFormatBMP
,PixelFormat24bppRGB
,标志imageflagsrealdly | ImageFlagsHasRealPixelSize | ImageFlagsHasRealDPI | imageflagscolorspactergb
,大小1024 x 1162=绘制中原始位图文件的大小。位图分辨率为72.0089951点/in,而graphics.GetDpiX()
显示96点/英寸。由于96/72=4/3,这可能导致不必要的放大。那么我该如何纠正这一点呢?我尝试了graphics.SetPageScale(72.0089951/96)
,但没有效果。