【发布时间】:2014-02-13 14:01:07
【问题描述】:
我希望这个问题以前没有被问过,我到处搜索。
我的问题是我在我的 wpf 用户控件上用点绘制了一组坐标,我设法用背景颜色填充了我的多边形,但没有用笔画。斯托克因为某种原因没有画画?
这是我使用 DrawingContext 处理 OnRender 事件的代码
System.Windows.Media.Pen penDrawing = new System.Windows.Media.Pen(System.Windows.Media.Brushes.OrangeRed, 2);
drawingContext.DrawGeometry(System.Windows.Media.Brushes.LightSeaGreen, penDrawing, streamGeometry);
代码详解
StreamGeometry streamGeometry = new StreamGeometry();
System.Windows.Point firstCoordinate = new System.Windows.Point();
System.Windows.Point lastCoordinateAdded = new System.Windows.Point();
bool isMainPolygon = true;
using (StreamGeometryContext geometryContext = streamGeometry.Open())
{
PointCollection points = new PointCollection();
firstCoordinate = new System.Windows.Point(coordinatePoints.ProjectedCoordinates[0].X, coordinatePoints.ProjectedCoordinates[0].Y);
geometryContext.BeginFigure(firstCoordinate, true, true);
System.Windows.Media.Pen penDrawing = new System.Windows.Media.Pen(System.Windows.Media.Brushes.OrangeRed, 5);
penDrawing.EndLineCap = PenLineCap.Round;
penDrawing.DashCap = PenLineCap.Round;
penDrawing.LineJoin = PenLineJoin.Round;
penDrawing.StartLineCap = PenLineCap.Round;
penDrawing.MiterLimit = 10.0;
for (int i = 1; i < coordinatePoints.ProjectedCoordinates.Count; i++)
{
lastCoordinateAdded = new System.Windows.Point() { X = coordinatePoints.ProjectedCoordinates[i].X, Y = coordinatePoints.ProjectedCoordinates[i].Y };
points.Add(lastCoordinateAdded);
//////Check to see if Polygon is done drawing
if (firstCoordinate == lastCoordinateAdded)
{
geometryContext.PolyLineTo(points, true, true);
//drawingContext.DrawGeometry(isMainPolygon ? System.Windows.Media.Brushes.Green : System.Windows.Media.Brushes.White, pen, streamGeometry);
streamGeometry.Freeze();
drawingContext.DrawGeometry(null, penDrawing, streamGeometry);
points = new PointCollection();
streamGeometry = new StreamGeometry();
if (i + 1 < coordinatePoints.ProjectedCoordinates.Count)
{
i++;
isMainPolygon = false;
firstCoordinate = new System.Windows.Point(coordinatePoints.ProjectedCoordinates[i].X, coordinatePoints.ProjectedCoordinates[i].Y);
geometryContext.BeginFigure(firstCoordinate, true, true);
}
}
}
geometryContext.PolyLineTo(points, true, true);
}
coordinatePoints.State = Enums.CoordinateEnum.None;
}
我很乐意提供更多细节。
谢谢一百万。
【问题讨论】:
-
你没看到的是橙红色?为什么不让它的大小超过 2?
-
@Rui 我想看看生成几何图形的代码。图形段是否设置为描边?
-
几何的范围是多少?我相信笔触宽度可能会缩小很多以适应它变得不可见的程度。
-
我可能正在做一个比例转换,但我确实将笔画大小设置为 100 之类的东西。我确实将填充删除为空,看看我是否可以看到笔画没有运气.谢谢大家的帮助
-
@500 - 内部服务器错误 感谢一百万,我将 stoke 大小增加到 200,放大时我可以看到这条线。如果您发布为答案,我将标记为正确的:)
标签: c# wpf polygon stroke drawingcontext