Click to See Complete Forum and Search --> : How to produce alpha channel effect?
dc_2000
May 4th, 2006, 10:17 PM
Say, I have an image pixel imgP = RGB(im_r, im_g, im_b); it's alpha channel
value achP = RGB(ach_r, ach_g, ach_b); and the background pixel bkgP =
RGB(bg_r, bg_g, bg_b)
How do I combine them to produce alpha channel blending?
CBasicNet
May 5th, 2006, 12:34 AM
The alpha algorithm is written in MSDN,
SCA is alpha value of range from 0.0 to 255.0. 0 means source is fully transparent and 255 means the source is fully opaque.
Dst.Red = Src.Red * (SCA/255.0) + Dst.Red * (1.0 - (SCA/255.0))
Dst.Green = Src.Green * (SCA/255.0) + Dst.Green * (1.0 - (SCA/255.0))
Dst.Blue = Src.Blue * (SCA/255.0) + Dst.Blue * (1.0 - (SCA/255.0))
You need not write your own function, you can use the GDI function, called AlphaBlend().
CBasicNet
May 5th, 2006, 12:42 AM
You can rearrange the formula algebraically, to remove 1 division and remove all the float and int conversion by using int only.
Result = (SrcRed * Alpha + DstRed * (255 - Alpha))/255
I just show the red component as the formula is the same for other 2 color components.
dc_2000
May 5th, 2006, 02:24 AM
Hey, thanks a lot. That's exactly what I needed. I was trying to find it in MSDN without any luck. Do you by any chance know the link there?
CBasicNet
May 5th, 2006, 03:18 AM
Here it is,
BLENDFUNCTION struct (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_3b3m.asp)
golanshahar
May 5th, 2006, 04:23 AM
This thread (http://www.codeguru.com/forum/showthread.php?t=327701) can also help.
Cheers
dc_2000
May 5th, 2006, 02:58 PM
AWSOME! Thanks again.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.