Color Alpha Blend - CSharp System.Drawing

CSharp examples for System.Drawing:Color

Description

Color Alpha Blend

Demo Code


using Windows.UI;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w  w  w  .ja  va  2 s. com

public class Main{
        public static Color AlphaBlend(Color color1, Color color2, byte alpha)
        {
            float factor = alpha / 255f;
            byte red = (byte)(color1.R * (1 - factor) + color2.R * factor);
            byte green = (byte)(color1.G * (1 - factor) + color2.G * factor);
            byte blue = (byte)(color1.B * (1 - factor) + color2.B * factor);
            return Color.FromArgb(0xFF, red, green, blue);
        }
        public static Color AlphaBlend(Color color1, Color color2)
        {
            return AlphaBlend(color1, color2, color2.A);
        }
}

Related Tutorials