Solved

BitBlt Flickering

Posted on 2004-10-06
11
536 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
Comment Utility
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
Comment Utility
Please show your code with using of memory bitmap.
0
 

Author Comment

by:skirmish76
Comment Utility
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
 

Author Comment

by:skirmish76
Comment Utility
*bump*
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:skirmish76
Comment Utility
Flicker free blitting anyone?
0
 
LVL 1

Expert Comment

by:Koro_das_Master
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now