skirmish76
asked on
BitBlt Flickering
I want to blit a transparent button (a round button) using a monochrome mask. This code works:
<cpp>
SelectObject(hDCSrc, hBMP); //copy HBITMAP's DC
SelectObject(hDCMsk, hMask); //copy monochrome bitmap's DC
BitBlt(hDCDst, 0, 0, uBMPWid, uBMPHgt, hDC, 0, 0, SRCAND); //blit mask with &
BitBlt(hDCDst, 0, 0, uBMPWid, uBMPHgt, hDC, 0, 0, SRCPAINT); //paint to set bits
</cpp>
but it flickers. I have spent the last few hours googling for solutions to no avail.
I have tried rendering to a HBITMAP in memory but it seems to ignore alpha. I tried MaskBlt but the only MAKEROP4 combos that would work were SRCCOPY, SRCCOPY, not terribly useful for transparent blitting.
I am using standard Win32 not MFC.
Any suggestions will be greatly appreciated.
Thanks
-A-
<cpp>
SelectObject(hDCSrc, hBMP); //copy HBITMAP's DC
SelectObject(hDCMsk, hMask); //copy monochrome bitmap's DC
BitBlt(hDCDst, 0, 0, uBMPWid, uBMPHgt, hDC, 0, 0, SRCAND); //blit mask with &
BitBlt(hDCDst, 0, 0, uBMPWid, uBMPHgt, hDC, 0, 0, SRCPAINT); //paint to set bits
</cpp>
but it flickers. I have spent the last few hours googling for solutions to no avail.
I have tried rendering to a HBITMAP in memory but it seems to ignore alpha. I tried MaskBlt but the only MAKEROP4 combos that would work were SRCCOPY, SRCCOPY, not terribly useful for transparent blitting.
I am using standard Win32 not MFC.
Any suggestions will be greatly appreciated.
Thanks
-A-
Please show your code with using of memory bitmap.
ASKER
I wiped that code so this is going from memory:
<cpp>
//--- AT LOAD TIME ---//
//I had to create it from a resource because using CreateBitmap wasn't working regardless
//of the params I passed to it
hBMPMem = (HBITMAP)LoadImage(GetModu leHandle(N ULL), MAKEINTRESOURCE(IDBMPSAMPL E), IMAGE_BITMAP, 0, 0, 0);
hDCMem = CreateCompatibleDC(GetDC(h Wnd));
SelectObject(hDCMem , hBMPMem);
BitBlt(hDCMem, 0, 0, uBMPWid, uBMPHgt, hDCMask, 0, 0, SRCAND);
BitBlt(hDCMem, 0, 0, uBMPWid, uBMPHgt, hDCImage, 0, 0, SRCPAINT);
//--- AT DRAW TIME ---//
return BitBlt(hDCDst, 0, 0, uBMPWid, uBMPHgt, hDCMem, 0, 0, SRCCOPY);
</cpp>
This drew the image but without transparency, ie as if I blitted hDCImage to hDCDst with SRCCOPY and skipped all the other steps.
<cpp>
//--- AT LOAD TIME ---//
//I had to create it from a resource because using CreateBitmap wasn't working regardless
//of the params I passed to it
hBMPMem = (HBITMAP)LoadImage(GetModu
hDCMem = CreateCompatibleDC(GetDC(h
SelectObject(hDCMem , hBMPMem);
BitBlt(hDCMem, 0, 0, uBMPWid, uBMPHgt, hDCMask, 0, 0, SRCAND);
BitBlt(hDCMem, 0, 0, uBMPWid, uBMPHgt, hDCImage, 0, 0, SRCPAINT);
//--- AT DRAW TIME ---//
return BitBlt(hDCDst, 0, 0, uBMPWid, uBMPHgt, hDCMem, 0, 0, SRCCOPY);
</cpp>
This drew the image but without transparency, ie as if I blitted hDCImage to hDCDst with SRCCOPY and skipped all the other steps.
ASKER
*bump*
ASKER
Flicker free blitting anyone?
You could create a memory DC of the size of the bitmap you want to draw, copy the area that would be "under" the bitmap from the screen to that DC, then, blit your bitmap in that DC, then finally copy the DC contents to the screen. No flickering, since you only write once to the screen.
ASKER
Hmmm I am pretty sure that won't work because the blit would just overwrite all of the pixels in the DC not just the ones that corresponded to non-transparent pixels in the source.
I can't believe I haven't found a good solution for this yet. I am tempted to cheat and paint the background into the bitmaps before runtime hence requiring only one blit. I would like to avoid this though simply on the basis of principle.
I can't believe I haven't found a good solution for this yet. I am tempted to cheat and paint the background into the bitmaps before runtime hence requiring only one blit. I would like to avoid this though simply on the basis of principle.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I didn't find that the solution worked for me so I found a workaround without transparency. But I recognise Koros took time to give me suggestions so can I split the points half refund half Koros. If that isn't possible give them to Koros.
ASKER
points_value++