在GDI+中绘制带渐变的折线;

发布于 2024-09-08 02:32:51 字数 644 浏览 3 评论 0原文

我有一个包含多个点的 List 。如何将这些点绘制到位图中,以获得与此相同的效果:

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

点是已知的,我只需要以某种方式实现这种渐变效果。

请注意,渐变不是径向的,如果将折线解开为直线,您将获得从一端到另一端的简单线性渐变。我只需要沿着线的“断点”扭转这个线性渐变。

我当前的解决方案是单独绘制每条线,同时计算正确的开始颜色结束颜色< /em> 每条线,因此我可以使用 LinearGradientBrush,然后使用 DrawLine


1) 除了自己计算颜色之外,还有其他解决方案吗?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初熏 2024-09-15 02:32:51

关于圆角末端,您可以为您的笔设置此属性,

    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

以便您可以在图像上更改画布笔。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文