Link to home
Start Free TrialLog in
Avatar of skirmish76
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-
Avatar of skirmish76
skirmish76

ASKER

ok maybe this one is a bit tricky but I know some of you win32 gurus would have nailed this back in the mid-90s

points_value++
Please show your code with using of memory bitmap.
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(GetModuleHandle(NULL), MAKEINTRESOURCE(IDBMPSAMPLE), IMAGE_BITMAP, 0, 0, 0);
hDCMem = CreateCompatibleDC(GetDC(hWnd));
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.
*bump*
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Koro_das_Master
Koro_das_Master

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.