Solved

BitBlt Flickering

Posted on 2004-10-06
11
537 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
 

Author Comment

by:skirmish76
ID: 12270342
*bump*
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

863 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

27 Experts available now in Live!

Get 1:1 Help Now