简体   繁体   English

用渐变色绘制线条

[英]Drawing a line with a gradient color

Is it possible to draw a line using a graduated colour? 是否可以使用渐变色绘制线条?

I want to be able to draw a straight or a curved line (if possible) where at one end of the line is Blue and the other end is Red. 我希望能够绘制直线或曲线(如果可能),在该线的一端是蓝色,另一端是红色。

Further There might be a need to have more than one gradient per-line eg the colour going from Blue -> Green -> Red. 此外,可能需要每行有多个渐变,例如颜色来自蓝色 - >绿色 - >红色。 I am thinking that this might just consist of multiple gradient lines drawn together. 我想这可能只是由多个渐变线组成。

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    Graphics graphicsObject = e.Graphics;

    using (Brush aGradientBrush = new LinearGradientBrush(new Point(0, 0), new Point(50, 0), Color.Blue, Color.Red))
    {
        using (Pen aGradientPen = new Pen(aGradientBrush))
        {
            graphicsObject.DrawLine(aGradientPen, new Point(0, 10), new Point(100, 10));
        }
    }
}

you will need to use System.Drawing.Drawing2D.LinearGradientBrush instead of System.Drawing.SolidBrush 您将需要使用System.Drawing.Drawing2D.LinearGradientBrush而不是System.Drawing.SolidBrush

example: 例:

e.Graphics.DrawLine(new Pen(new System.Drawing.Drawing2D.LinearGradientBrush(...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM