Solved

BitBlt Flickering

Posted on 2004-10-06
11
538 Views
Last Modified: 2013-12-03
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-
0
Comment
Question by:skirmish76
  • 6
  • 2
11 Comments
 

Author Comment

by:skirmish76
ID: 12245868
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++
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 12246173
Please show your code with using of memory bitmap.
0
 

Author Comment

by:skirmish76
ID: 12246429
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.
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

Author Comment

by:skirmish76
ID: 12270342
*bump*
0
 

Author Comment

by:skirmish76
ID: 12327480
Flicker free blitting anyone?
0
 
LVL 1

Expert Comment

by:Koro_das_Master
ID: 12344207
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.
0
 

Author Comment

by:skirmish76
ID: 12382407
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.
0
 
LVL 1

Accepted Solution

by:
Koro_das_Master earned 155 total points
ID: 12383417
That's why you "prepare" the memory DC by copying what would be under the bitmap from the destination DC on it before doing your transparent blit. That way, when you copy it back to the destination DC, yes, you overwrite all the pixels BUT, since where there is transparency they are the same as on the destination DC, thus achieving the desired transparency effect.
0
 

Author Comment

by:skirmish76
ID: 12816846
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.
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
catastrophic failure exception from hresult 0x8000ffff e_unexpected 9 109
wordpress limitations 4 115
GUI: DIalog Stacking and Popping in MS C++ 4 76
Question to Pivot table 1 53
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question