为什么在内存位图上绘图并不像预期的那样工作?

时间:2015-05-12 13:17:29

标签: c++ gdi+

我试图在内存位图上绘图并得到奇怪的结果。这是我的代码:

HDC hdcScreen = GetDC(hWnd);
HDC hdcMemory = CreateCompatibleDC(hdcScreen);
HBITMAP hMemoryBitmap = CreateCompatibleBitmap(hdcScreen, w, h);

HBITMAP hBitmapOld = (HBITMAP)SelectObject(hdcMemory, hMemoryBitmap);

Graphics *memoryGraphics = Graphics::FromHDC(hdcMemory);
SolidBrush brush(Color(255, 255, 0, 0));
memoryGraphics->FillRectangle(&brush, 0, 0, w, h);

POINT dcOffset = { 0, 0 };
SIZE size = { w, h };
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 255;
bf.AlphaFormat = AC_SRC_ALPHA;

UpdateLayeredWindow(hWnd, hdcScreen, &dcOffset, &size, hdcMemory, &dcOffset, 0, &bf, ULW_ALPHA);

delete memoryGraphics;
ReleaseDC(hWnd, hdcScreen);
SelectObject(hdcMemory, hBitmapOld);
DeleteDC(hdcMemory);
DeleteObject(hMemoryBitmap);

它让我半透明!为什么?我在画笔中清楚地指定了Color(255, 255, 0, 0)

0 个答案:

没有答案