Change Color Brightness - CSharp System.Drawing

CSharp examples for System.Drawing:Color Brightness

Description

Change Color Brightness

Demo Code


using System.Text.RegularExpressions;
using System.Linq;
using System.Drawing;
using System;/*from   w  ww.j a v  a2s . c om*/

public class Main{
        public static Color ChangeColorBrightness(Color color, float correctionFactor)
        {
            var red = (float)color.R;
            var green = (float)color.G;
            var blue = (float)color.B;

            if (correctionFactor < 0)
            {
                correctionFactor = 1 + correctionFactor;
                red *= correctionFactor;
                green *= correctionFactor;
                blue *= correctionFactor;
            }
            else
            {
                red = (255 - red) * correctionFactor + red;
                green = (255 - green) * correctionFactor + green;
                blue = (255 - blue) * correctionFactor + blue;
            }

            return Color.FromArgb(color.A, (int)red, (int)green, (int)blue);
        }
}

Related Tutorials