Returns the result of combining the specified colors - CSharp System.Drawing

CSharp examples for System.Drawing:Color

Description

Returns the result of combining the specified colors

Demo Code


using System.Windows.Media;
using System.Windows;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System;//w ww  .j  a v a2 s .co m

public class Main{
        #region Static

        /// <summary>
        /// Returns the result of combining the specified colors
        /// </summary>
        /// <param name="c1">First color to combine</param>
        /// <param name="c2">Second olor to combine</param>
        /// <returns>Average of both colors</returns>
        public static Color Combine(Color c1, Color c2)
        {
            return Color.FromArgb(
                Convert.ToByte((c1.R + c2.R) / 2),
                Convert.ToByte((c1.G + c2.G) / 2),
                Convert.ToByte((c1.B + c2.B) / 2),
                Convert.ToByte((c1.A + c2.A) / 2)
                );
        }
}

Related Tutorials