• Advertisement
Sign in to follow this  

C++ and Win32 GDI

This topic is 3314 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I need your help to solve the problem depicted below. Imagine you have a bitmap and you want to apply a colour-key and trasparency via alpha channel at the same time, coz you have a red circle on a black bkg and you want to see only the red circle with some degree of alpha blending on a blue bkg. Hope I've described the scenario well enough. I got a dive in the Win32 GDI docs and I've found out two APIs which I think I could use, that is: TransparentBlt() and AlphaBlend(). I wrote my code as below ( I provided the pseudocode here ) 1. Load the bitmap from file 2. Achieve the DC in the WM_PAINT message handler 3. Create a memory compatible DC 4. Select the bitmap in the aforementioned DC 5. Create another memory compatible DC 6. Create a compatible (with the DC achieved at point 2) bitmap 7. Select the bitmap from point 6 in the DC from point 5 8. Call TrasparentBlt using the DC at point 3 as source and the DC at point 5 as destination. 9. Call AlphaBlending using the DC at point 5 as source and the DC at point 2 as destination. Given that the memory compatible DC as a black bkg, no more effort is needed to understand that the colour-keying operation is overriden giving a wrong result i.e. the red circle and its bkg are displayed both with some degree of alpha blending. Could you please help me to get the result I need? Is there a way to create something like a transparent DC in memory? Does the use of a bitmask solve the problem? Thanks in advance for your precious help it is really appreciated. Best Regards - FB

Share this post


Link to post
Share on other sites
Advertisement
The GDI doesn't do transparency very well at all - as in it almost certainly won't work, and if it works on e.g. XP it almost certainly won't work on '98 or Vista. Your best bet is to save yourself a lot of time and headaches and just do all colour keying manually by using a DIB section to get access to the bits for your image and working otu each pixel colour yourself.

Alternatively, use OpenGL or Direct3D to do transparent rendering.

Share this post


Link to post
Share on other sites
Hi Steve,
thanks for your reply.
Two things,
1) I forgot to say that I'm working on an embedded system which doesn't contain any H/W support for rendering so using either OpenGL ES or Direct3D Mobile is a pain. I've already tried, and, trust me, rendering just one shaded rotating tringle simply sucks...so I gave up with such APIs
2) I think that your suggestion to manage every single pixel would work but what about performance?

Do you have any code snippet I can use as learning material?

Best Regards
- FB

[Edited by - FrancescoB on January 27, 2009 1:45:43 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement