Decreases the luminosity of a color by a specified amount. - CSharp System.Drawing

CSharp examples for System.Drawing:Color Brightness

Description

Decreases the luminosity of a color by a specified amount.

Demo Code


using Microsoft.Xna.Framework;
using System;/*from w w w  .ja  v a 2 s .  c o  m*/

public class Main{
        /// <summary>
        /// Decreases the luminosity of a color by a specified amount.
        /// </summary>
        public static Color Darken(this Color color, float amount)
        {
            return new Color(color.ToVector3() * (1 - amount));
        }
        /// <summary>
        /// Decreases the luminosity of a color by a random amount that is between a specified range.
        /// </summary>
        public static Color Darken(this Color color, float minAmount, float maxAmount)
        {
            return Darken(color, (float)Random.NextDouble() * (maxAmount - minAmount) + minAmount);
        }
        /// <summary>
        /// Decreases the luminosity of a color by a random amount.
        /// </summary>
        public static Color Darken(this Color color)
        {
            return Darken(color, 0, 1);
        }
}

Related Tutorials