将ARGB转换为RGB而不会丢失信息

roq*_*str 6 c# colors windows-phone-7

我尝试将argb值转换为rgb值而不会丢失它从背景中获取的信息.所以例如:背景是黑色的,argb是(150,255,0,0),结果我不想有一种棕色.

有没有机会处理这个?

How*_*ard 7

你可以算一算

foreground * alpha + background * (1-alpha)
Run Code Online (Sandbox Code Playgroud)

作为红色,绿色和蓝色通道的新颜色.请注意,我使用的alpha缩放,以01在表达式.


Ric*_*ter 6

    public static Color RemoveAlpha(Color foreground, Color background)
    {
        if (foreground.A == 255)
            return foreground;

        var alpha = foreground.A / 255.0;
        var diff = 1.0 - alpha;
        return Color.FromArgb(255,
            (byte)(foreground.R * alpha + background.R * diff),
            (byte)(foreground.G * alpha + background.G * diff),
            (byte)(foreground.B * alpha + background.B * diff));
    }
Run Code Online (Sandbox Code Playgroud)

来自http://mytoolkit.codeplex.com/SourceControl/latest#Shared/Utilities/ColorUtility.cs