简体   繁体   中英

Drawing polygonal line with gradient in GDI+

I have a List<Point> of multiple points. How can I draw these points into a bitmap, to get the same as this:

http://img291.imageshack.us/img291/4462/outputtz.png

Points are known, I just need to achieve this gradient effect somehow.

Please note that the gradient isn't radial, if you untwist the polygonal line to a straight one, you would get simple linear gradient from one end to another. I just need this linear gradient twisted along the line's "breaking points".

My current solution is drawing each line separately, while calculating the proper start-color and end-color for each line, so I can use LinearGradientBrush and then DrawLine .


1) Is there any other solution, than calculating the colors myself?

2) How to draw a line with round ends (as on image)? My solution is by drawing ordinary line, with ellipse on each end, but those ellipses won't have gradient, so if the line is VERY short, there is no gradient.

About the rounded ends you can set this property for you Pen

    Graphics g = e.Graphics;
    Pen p = new Pen(Color.Brown, 15);

    // round ends
    p.StartCap = LineCap.Round;
    p.EndCap = LineCap.Round;
    g.DrawLine(p, 30, 80, Width - 50, 80);//can be replace with you code

so on your image you can change the canvas pen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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