주어진 윈도우 내에 버퍼 (알파 정보 포함)를 그려야합니다. 드로잉은 WM_PAINT 외부에서 수행됩니다 (Chromium-Embedded-Framework에서 호출 된 CefRenderHandler :: OnPaint 메서드에서 수행됩니다). 내가 가진 것을버퍼를 사용하는 Windows AlphaBlend
문제는 다음과 같습니다 창의
- 된 내용 (버퍼가 변경되면, 나는 오래된 내용이 그려 새로운 내용이 그려 얻을) 지워지지 않습니다.
- 알파 채널이 잘못 해석 - 나는 픽셀이 알파 정보가있는 경우에도 그것이 알파 정보
이가없는 것처럼,이 그려진 것으로, 생각은 내가 지금까지 무엇을 가지고 :
의 OnPaint (...)
HDC screen_dc = GetDC(windowHandle);
RECT rcWin;
GetClientRect(windowHandle, &rcWin);
BITMAPINFO info;
ZeroMemory(&info, sizeof(BITMAPINFO));
info.bmiHeader.biBitCount = 32;
info.bmiHeader.biWidth = width;
info.bmiHeader.biHeight = -height;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biSizeImage = width*height * 4;
info.bmiHeader.biCompression = BI_RGB;
void *buf;
HBITMAP hDib = CreateDIBSection(screen_dc, &info, DIB_RGB_COLORS, (void **)&buf, 0, 0);
memcpy(buf, buffer, width * height * 4); //buffer contains bitmap to draw
HDC hDibDC = CreateCompatibleDC(screen_dc);
HGDIOBJ hOldObj = SelectObject(hDibDC, hDib);
BLENDFUNCTION blendFunction_;
blendFunction.BlendOp = AC_SRC_OVER;
blendFunction.BlendFlags = 0;
blendFunction.SourceConstantAlpha = 255;
blendFunction.AlphaFormat = AC_SRC_ALPHA;
AlphaBlend(screen_dc, 0, 0, width, height, hDibDC, 0, 0, width, height, blendFunction);
SelectObject(hDibDC, hOldObj);
ReleaseDC(windowHandle, screen_dc);
DeleteObject(hDib);
DeleteDC(hDibDC);
윈도우 생성 :
WNDCLASSEX wcex = {0};
wcex.cbSize = sizeof(wcex);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = BrowserWindowWndProc;
wcex.hInstance = hinstance;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = WHITE_BRUSH;
wcex.lpszClassName = BROWSER_WINDOW_CLASS;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
RegisterClassEx(&wcex);
DWORD exStyle{0};
exStyle |= WS_EX_TOOLWINDOW;
exStyle |= WS_EX_LAYERED;
DWORD style {0};
style |= WS_SYSMENU;
style |= WS_VISIBLE;
HWND hWnd = CreateWindowEx(
exStyle,
BROWSER_WINDOW_CLASS,
BROWSER_WINDOW_CLASS,
style,
100,
100,
300,
300,
nullptr,
nullptr,
hinstance,
nullptr
);
...
SetLayeredWindowAttributes(hWnd, RGB(255, 255, 255), 255, LWA_COLORKEY);
,
이러한 문제를 해결해 주시겠습니까?
미리 감사드립니다.
의 OnPaint에서 당신은 BeginPaint 함수의 기능을 대신의 GetDC를 사용하는 촬영 HDC를 사용해야합니다. 이렇게하면 배경 내용의 문제가 해결 될 수 있습니다. 잘못된 알파 값에 대해서는 다음과 같이 비트 맵에 알파 값을 미리 곱해야합니다. http://www.fengyuan.com/article/alphablend.html – VuVirt