Pixel Transparency with Alpha

Started by
2 comments, last by nts 19 years, 4 months ago
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
My signature used to suck. But it's much better and more accurate now.
Advertisement
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

There is no such thing as SRC_ALPHA_MINUS_ONE. And, if you are telling me that I can make such a constant, what would it's value be?

My signature used to suck. But it's much better and more accurate now.
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

This topic is closed to new replies.

Advertisement