2

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.

Paya
  • 5,124
  • 4
  • 45
  • 71

1 Answers1

1

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.

Sara S.
  • 1,365
  • 1
  • 15
  • 33
  • Thanks, +1, that solves the second question. But what about the first one? – Paya Jun 02 '11 at 12:40
  • Accepted your answer - I believe there is no other solution for the first question. – Paya Sep 08 '12 at 12:58
  • did you try to draw a gradient bitmap separately then AND it with a bitmap where you draw your line in white and the rest is black so the gradient of the first bitmap will be shown, it's time consuming but it's easier in calculation and u can find a fast algorithm of Anding rather than looping over the width and height .just try it – Sara S. Sep 24 '12 at 08:15
  • But how do you suggest I should draw the gradient? Of course what I do is not drawing the whole gradient by myself - by calculating the colors I meant the start and end color of each line, and then use linear gradient for each line separately ... instead of just using one gradient for the whole thing, which is what I was looking for. – Paya Sep 26 '12 at 15:56
  • Of course I have already read MSDN on all Gradient classes, including your article, but that doesn't really help that much. As far as I understand, path gradient doesn't allow you to make just any gradient you please. If you were able to get it to do what I need then please share your code, because I couldn't. The line I need to draw doesn't necessarily have to look like the one in the original question, just imagine any line, but with same gradient blue to green from one end to the other. – Paya Sep 29 '12 at 13:53