Solved

BitBlt Flickering

Posted on 2004-10-06
11
540 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

827 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