How to calculate an RGB colour by specifying an alpha blending amount?

前端 未结 3 2190
执念已碎
执念已碎 2020-11-27 10:41

I\'m writing a colour picker that gets the pixel RGB values from wherever you point to on the screen. I want to also have the option of specifying that the colour I picked

3条回答
  •  感动是毒
    2020-11-27 11:07

    The following pseudo-code resolves your problem:

        CalculateSolidColorFromTransparentColor(Color color, Color background)
        {
            alpha = color.A / 255;
            oneminusalpha = 1 - alpha;
    
            newR = ((color.R * alpha) + (oneminusalpha * background.R));
            newG = ((color.G * alpha) + (oneminusalpha * background.G));
            newB = ((color.B * alpha) + (oneminusalpha * background.B));
        }
    

    Note that input color and backgroud has values expressed in [0..255]

提交回复
热议问题