Raster methods and transparency Win32 C ++ BitBlt

I recently asked a question about this and understood the answer, but could not translate it into code. After another day, messing around with things and fixing leaks. I literally cannot, because life understands this.

This is a little different, all I have to do is get a bitmap of the background under the map bitmap. What i have

HDC hdc = GetDC(hWnd);
HDC hdcMem = CreateCompatibleDC(hdc);
HDC hdcMem2 = CreateCompatibleDC(hdc);
ReleaseDC(hWnd, hdc);

HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, bitmap.hbmBackground);
BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem, 0, 0, SRCCOPY);       

HBITMAP hbmOld2 = (HBITMAP)SelectObject(hdcMem2, bitmap.hbmMap);
BitBlt(buffer.getBufferDC(), 1, 1, WINDOW_WIDTH, WINDOW_HEIGHT, hdcMem2, 0, 0, SRCPAINT); 

SelectObject(hdcMem2, hbmOld2);

My problem is combining ... creating dcs memory to save the results of raster operations. I generally can not wrap my head around, any help will be great.

Thank.

+3
source share
1 answer

, . - , , , .

, , . , ( , ), . , RGB 254, 254, 254 - (255, 255, 255), .

, : TransparentBlt , BitBlt, TransparentBlt. ( , ) :

HDC mask, background, combined;

mask =       CreateCompatibleDC(screen);
background = CreateCompatibleDC(screen);
combined =   CreateCompatibleDC(screen);

HBITMAP mask_bmp = LoadBitmap(MAKEINTRESOURCE(IDB_MASK));
HBITMAP back_bmp = LoadBitmap(MAKEINTRESOURCE(IDB_BKGND));
HBITMAP result = CreateCompatibleBitmap(screen);

mask_original = Selectobject(mask, mask_bmp);
back_original = SelectObject(background, back_bmp);
combined_original = SelectObject(combined, result);

BitBlt(background, result, SRCCOPY);
TransparentBlt(mask, result, RGB(254, 254, 254));

BitBlt(result, screen, SRCCOPY);

SelectObject(mask, mask_original);
SelectObject(background, back_original);
SelectObject(combined, combined_original);

DeleteDC(mask);
DeleteDC(background);
DeleteDC(combined):
DeleteObject(result);
+4

All Articles