题
让我们说,我们有一个将斜角色:
Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.
当这个是画在现有的颜色颜色的融合。所以当它是配合有白色,得到的颜色是 Color.FromARGB(255, 162, 133, 255);
该解决方案应该作这样的:
Color blend = Color.White;
Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.
Color rgb = ToRGB(argb, blend); //Same as Color.FromARGB(255, 162, 133, 255);
是什么 ToRGB
's执行?
解决方案
这就是所谓 alpha blending.
在psuedocode,假定的背景的颜色(混)始终有255阿尔法。也假定阿尔法0到255。
alpha=argb.alpha()
r = (alpha/255)*argb.r() + (1 - alpha/255)*blend.r()
g = (alpha/255)*argb.g() + (1 - alpha/255)*blend.g()
b = (alpha/255)*argb.b() + (1 - alpha/255)*blend.b()
注:你可能需要一点(多个)小心浮点/int数学和四舍五入的问题,取决于语言。铸造的中间体,因此
编辑,以增加:
如果你没有背景的颜色有一个阿尔法的255,代数变得更为复杂。我以前做过,它的一个有趣的锻炼留给读者(如果你真的需要知道,你问另一个问题:).
换句话说,是什么颜色C融合到一些背景相同的混合,然后混B。这就像计算的A+B(其不同作为B+A)。
其他提示
我知道这是一个旧线,但我要添加这样的:
Public Shared Function AlphaBlend(ByVal ForeGround As Color, ByVal BackGround As Color) As Color
If ForeGround.A = 0 Then Return BackGround
If BackGround.A = 0 Then Return ForeGround
If ForeGround.A = 255 Then Return ForeGround
Dim Alpha As Integer = CInt(ForeGround.A) + 1
Dim B As Integer = Alpha * ForeGround.B + (255 - Alpha) * BackGround.B >> 8
Dim G As Integer = Alpha * ForeGround.G + (255 - Alpha) * BackGround.G >> 8
Dim R As Integer = Alpha * ForeGround.R + (255 - Alpha) * BackGround.R >> 8
Dim A As Integer = ForeGround.A
If BackGround.A = 255 Then A = 255
If A > 255 Then A = 255
If R > 255 Then R = 255
If G > 255 Then G = 255
If B > 255 Then B = 255
Return Color.FromArgb(Math.Abs(A), Math.Abs(R), Math.Abs(G), Math.Abs(B))
End Function
public static Color AlphaBlend(Color ForeGround, Color BackGround)
{
if (ForeGround.A == 0)
return BackGround;
if (BackGround.A == 0)
return ForeGround;
if (ForeGround.A == 255)
return ForeGround;
int Alpha = Convert.ToInt32(ForeGround.A) + 1;
int B = Alpha * ForeGround.B + (255 - Alpha) * BackGround.B >> 8;
int G = Alpha * ForeGround.G + (255 - Alpha) * BackGround.G >> 8;
int R = Alpha * ForeGround.R + (255 - Alpha) * BackGround.R >> 8;
int A = ForeGround.A;
if (BackGround.A == 255)
A = 255;
if (A > 255)
A = 255;
if (R > 255)
R = 255;
if (G > 255)
G = 255;
if (B > 255)
B = 255;
return Color.FromArgb(Math.Abs(A), Math.Abs(R), Math.Abs(G), Math.Abs(B));
}
如果你不需要知道这种预渲染,你总是可以使用win32方法的getpixel,我相信。
注:打字在iPhone上的在中间的密苏里州没有inet的访问。会看起来真正的win32例,看看是否有一个.净相当。
在情况下,任何人都关心,并且不要使用)(优良)回答公布上述,可以得到的颜色价值的像素。净通过这个的链接 MSDN例
不隶属于 StackOverflow