AlphaBlend() strange colors.
-
Hello:) I have a gradient-like background with an owner drawn button. I use AlphaBlend() to draw button's image. Now, the strange thing is: Background pixel = RGB(168,168,168) Source pixel = 0xFFFF0000 (AARRGGBB) After AlphaBlend() with SourceConstantAlpha=0xff the output is RGB(255,0,0) - that's correct but when I change a bit the source pixel to Source pixel = 0x00FF0000 (AARRGGBB) I receive pixel RGB(255,168,168)?!?! I should get RGB(168,168,168) because the source alpha is 0x00?!?!? After some tests with different RGB values, I noticed that my blending works like it 'thinks' that my background is white (255,255,255)?!? When I make all source pixels to have 0xFF alpha value and just play with SourceConstantAlpha value, it's working fine!?! - my button is drawn with proper transparency?!? I need to play a bit with the source pixels' alpha value for 'soft' button's border. Does anyone know what could be wrong?? I'm using winxp/vs2003 Thanks a lot!!
-
Hello:) I have a gradient-like background with an owner drawn button. I use AlphaBlend() to draw button's image. Now, the strange thing is: Background pixel = RGB(168,168,168) Source pixel = 0xFFFF0000 (AARRGGBB) After AlphaBlend() with SourceConstantAlpha=0xff the output is RGB(255,0,0) - that's correct but when I change a bit the source pixel to Source pixel = 0x00FF0000 (AARRGGBB) I receive pixel RGB(255,168,168)?!?! I should get RGB(168,168,168) because the source alpha is 0x00?!?!? After some tests with different RGB values, I noticed that my blending works like it 'thinks' that my background is white (255,255,255)?!? When I make all source pixels to have 0xFF alpha value and just play with SourceConstantAlpha value, it's working fine!?! - my button is drawn with proper transparency?!? I need to play a bit with the source pixels' alpha value for 'soft' button's border. Does anyone know what could be wrong?? I'm using winxp/vs2003 Thanks a lot!!
AlphaBlend() from which class?
"Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")
-
AlphaBlend() from which class?
"Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")
Sorry, I couldn't reply as I was offline for couple of days. I was trying CDC::AlphaBlend(), CImage::AlphaBlend() and global ::AlphaBlend() with the same results. I discovered that I should premultiply r/g/b values by alpha channel. Now it works fine, but I wonder how to cope with the situation when You have very small r/g/b values and small alpha channel. When You premultiply those small values and divide by 255, You will get zeroes...Now if You want to recover almost transparent pixels by increasing their alpha value, You will get black color instead of original one?!?!? Am I correct?? Simple example: Source bitmap: ARGB(10,20,0,0) ; DARK RED After premultiply: ARGB(10,20*10/255,0,0) = ARGB(10,0,0,0); BLACK Now try to recover original color by increasing alpha ARGB(255,0,0,0) and You receive black instead of ARGB(255,20,0,0); Thanks for Your attention.
-
Sorry, I couldn't reply as I was offline for couple of days. I was trying CDC::AlphaBlend(), CImage::AlphaBlend() and global ::AlphaBlend() with the same results. I discovered that I should premultiply r/g/b values by alpha channel. Now it works fine, but I wonder how to cope with the situation when You have very small r/g/b values and small alpha channel. When You premultiply those small values and divide by 255, You will get zeroes...Now if You want to recover almost transparent pixels by increasing their alpha value, You will get black color instead of original one?!?!? Am I correct?? Simple example: Source bitmap: ARGB(10,20,0,0) ; DARK RED After premultiply: ARGB(10,20*10/255,0,0) = ARGB(10,0,0,0); BLACK Now try to recover original color by increasing alpha ARGB(255,0,0,0) and You receive black instead of ARGB(255,20,0,0); Thanks for Your attention.
Since you're essentially dividing pixel RGB values by 25.5 then yes, any values less than 25 are going to end up being 0. There's still something strange - I'm going to try your original code so I can see it. I'll be back. Mark
"Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")