How do I adjust the brightness of a color?

I would like to darken an existing color for use in a gradient brush. Could somebody tell me how to do this please?

C#, .net 2.0, GDI+

  Color AdjustBrightness(Color c1, float factor)
    {

        float r = ((c1.R * factor) > 255) ? 255 : (c1.R * factor);
        float g = ((c1.G * factor) > 255) ? 255 : (c1.G * factor);
        float b = ((c1.B * factor) > 255) ? 255 : (c1.B * factor);

        Color c  = Color.FromArgb(c1.A,(int)r, (int)g, (int)b);
        return c ;

    }

As a simple approach, you can just factor the RGB values:

    Color c1 = Color.Red;
    Color c2 = Color.FromArgb(c1.A,
        (int)(c1.R * 0.8), (int)(c1.G * 0.8), (int)(c1.B * 0.8));

(which should darken it; or, for example, * 1.25 to brighten it)


You could also try using

ControlPaint.Light(baseColor, percOfLightLight)

ControlPaint.Light

or

ControlPaint.Dark(baseColor, percOfDarkDark)

ControlPaint.Dark


Convert from RGB to HSV (or HSL), then adjust the V (or L) down and then convert back.

While System.Drawing.Color provides methods to get hue (H), saturation (S) and brightness it does not provide much in the way of other conversions, notable nothing to create a new instance from HSV (or HSV values), but the conversion is pretty simple to implement. The wikipedia articles give decent converage, starting here: "HSL and HSV".

链接地址: http://www.djcxy.com/p/51804.html

上一篇: 更改固定的任务栏图标(Windows 7)

下一篇: 如何调整颜色的亮度?