Interpolate color to new color - CSharp System.Drawing

CSharp examples for System.Drawing:Color

Description

Interpolate color to new color

Demo Code


using System.Drawing;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from  w  w w.  j  a v a 2s . co  m

public class Main{
        public static Color Interpolate(this Color from, float ratio, Color to)
        {
            var ratioNeg = 1 - ratio;

            return Color.FromArgb(
                (int)(from.A * ratioNeg + to.A * ratio),
                (int)(from.R * ratioNeg + to.R * ratio),
                (int)(from.G * ratioNeg + to.G * ratio),
                (int)(from.B * ratioNeg + to.B * ratio));
        }
}

Related Tutorials