Sign in to follow this  
ageny6

Pixel Transparency with Alpha

Recommended Posts

I've been trying for the longest time to alpha blit an image only using the GDI. My first successful attempt (after many failuires) used a DIB which was blended using additive blitting. It's wasn't true alpha blending, but it was close. However, this initial attempt was chattered by the awful complexity of the algorithm when images got big. Even with some MMX acceleration, the algo was still slow. Then, I stumbled upon the Alphablend function from the GDI. Got better FPS off the bat, but one problem emerged. With the algo discussed above, the additive blending took care of removing black pixels (made black pixels completely transparent), which was a desired effect (expecially for explosion animations and the such). However, with AlphaBlend, the black stays. I tried some tricks to remove the black background, but none were successful. The closes I got to actually solving the problem was creating a DIB, iterating through each pixel and if the color was black set the alpha = 0. Seemed like a good idea, but it didn't work. Now, I'm kinda freshed out. I've been stuck on this problem for a very long time, I have no more ideas. Any suggestions? Thanks

Share this post


Link to post
Share on other sites
I am not familiar with the alphablend functions from GDI but are you able to switch/set blending modes for the source and destination. If so then try out something like SRC_ALPHA for the source and SRC_ALPHA_MINUS_ONE for the destination.

HTH

Share this post


Link to post
Share on other sites
This might be helpful MSDN

Look at the blend functions at the bottom depending on what you have set. You probably want this one (or the first one, experiment and see which produces the correct result)

Quote:

If the source bitmap does not use SourceConstantAlpha (that is, it equals 0xFF), the per-pixel alpha determines the blend of the source and destination bitmaps, as shown in the following table.

Dst.Red = Src.Red + (1 - Src.Alpha) * Dst.Red
Dst.Green = Src.Green + (1 - Src.Alpha) * Dst.Green
Dst.Blue = Src.Blue + (1 - Src.Alpha) * Dst.Blue


HTH, Sorry i can't be more helpful, not really familiar with the GDI alpha blend functions

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this