Convert ARGB to RGB without losing information

12,228

Solution 1

You may calculate

foreground * alpha + background * (1-alpha)

as your new color for channels red, green and blue. Note that I used an alpha scaled to 0 to 1 in the expression.

Solution 2

    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));
    }

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

Share:
12,228
roqstr
Author by

roqstr

Business informatics student from germany. Mainly interested in mobile development and IT startups

Updated on June 12, 2022

Comments

  • roqstr
    roqstr almost 2 years

    i try to convert a argb value to a rgb-value without losing the information it got from his background. so for example: the background is black, the argb is (150,255,0,0) and as the result i wan't to have a kind of brown.

    is there any chance to deal with that?