通过将画笔的属性设置为 true
,可以为线性渐变画笔GammaCorrection启用伽马更正。 可以通过将 GammaCorrection 属性设置为false
来禁用伽马更正。 默认情况下禁用伽玛更正。
示例:
下面的示例是从控件的 Paint 事件处理程序调用的方法。 该示例创建线性渐变画笔,并使用该画笔填充两个矩形。 第一个矩形在没有伽玛更正的情况下填充,第二个矩形用伽玛更正填充。
下图显示了两个填充矩形。 顶部矩形没有伽玛更正,在中间显示为深色。 底部矩形具有伽玛修正,其强度似乎更统一。
public void FillTwoRectangles(PaintEventArgs e)
{
LinearGradientBrush linGrBrush = new LinearGradientBrush(
new Point(0, 10),
new Point(200, 10),
Color.Red,
Color.Blue);
e.Graphics.FillRectangle(linGrBrush, 0, 0, 200, 50);
linGrBrush.GammaCorrection = true;
e.Graphics.FillRectangle(linGrBrush, 0, 60, 200, 50);
}
Dim linGrBrush As New LinearGradientBrush( _
New Point(0, 10), _
New Point(200, 10), _
Color.Red, _
Color.Blue)
e.Graphics.FillRectangle(linGrBrush, 0, 0, 200, 50)
linGrBrush.GammaCorrection = True
e.Graphics.FillRectangle(linGrBrush, 0, 60, 200, 50)
编译代码
前面的示例设计用于 Windows 窗体,它需要 PaintEventArgse
,这是 Paint 事件处理程序的参数。