简体   繁体   English

用边框绘制折线

[英]Draw the Polyline with border

I'm using WPF to draw the polyline with certain width, the sample code is as follows: 我正在使用WPF绘制具有一定宽度的折线,示例代码如下:

DrawingContext.DrawGeometry(Brushes.Yellow, new Pen(Brush, polylineWidth), streamGeometry); DrawingContext.DrawGeometry(Brushes.Yellow,new Pen(Brush,polylineWidth),streamGeometry);

where the streamGeometry is the geometry of the polyline. 其中streamGeometry是折线的几何。 The result Looks like: 结果看起来像: 在此处输入图片说明

However, I'd like to add borders around the polyline, which looks like: 但是,我想在折线周围添加边框,如下所示:

在此处输入图片说明在此处输入图片说明

I know I can draw two polylines with different width (one for the black background, and the other for the color I want to render) I just wonder is there any API or some elegant way to achieve this? 我知道我可以绘制两条宽度不同的折线(一条用于黑色背景,另一条用于我要渲染的颜色),我只是想知道是否有任何API或某种优雅的方法可以实现这一点?

There is only one additional step needed to accomplish that. 仅需完成一个额外的步骤。 Create a new shape out of your polyline (the thickness of the polyline included). 用折线(包括折线的粗细)创建一个新形状。 Use: 采用:

var pathGeometry = streamGeometry.GetWidenedPathGeometry (new Pen(Brushes.Black, polylineWidth));

Then call 然后打电话

DrawingContext.DrawGeometry(Brushes.Yellow, new Pen(strokeBrush, strokeThickness), pathGeometry);

and you are done. 到此为止。

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

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