我正在使用SharpDX在.NET WinForms上绘制折线。 这些折线代表钣金件的轮廓。
组成PathGeometry对象,定义折线:
'reset m_pathGeometry (the core geometry of this sheetmetal profile)
m_pathGeometry = New PathGeometry(D2DCanvas.canvas_factory2D)
' pointsRef = collection of points showing the segments & bends in this sheetmetal profile
Dim pointsRef As List(Of Vector2) = calculateSegmentsPoints()
' Add lines to m_pathGeometry using our points collection
Using sink As SimplifiedGeometrySink = m_pathGeometry.Open()
sink.BeginFigure(pointsRef.First(), FigureBegin.Filled)
sink.AddLines(pointsRef.ToArray)
sink.EndFigure(FigureEnd.Open)
sink.Close()
End Using
在被绘制到屏幕之前,我应用了一个转换(考虑到转换和扩展):
' update m_fillTransformedGeometry based on m_pathGeometry & the current transform matrix3x2,
m_fillTransformedGeometry = New TransformedGeometry(D2DCanvas.canvas_factory2D, m_pathGeometry, Matrix3x2.Rotation(m_rotation, InsertPoint) * _transformMatrix)
' to draw the polyline
D2DCanvas.canvas_renderTarget2D.DrawGeometry(m_fillTransformedGeometry, m_fillBrush, plaatdikte * _transformMatrix.ScaleVector(1), m_strokeStyle)
使用描边样式,圆角线连接和平顶端
绘制折线With m_strokeStyleProps
.LineJoin = LineJoin.Round
.EndCap = CapStyle.Flat
.StartCap = CapStyle.Flat
End With
结果有点苍白,可以使用笔画:
第一个想法是用更深的颜色绘制相同的折线,稍微宽一点的StrokeWidth:
' First draw a wider stroke
D2DCanvas.canvas_renderTarget2D.DrawGeometry(m_fillTransformedGeometry, m_strokeBrush, (plaatdikte + 0.2) * _transformMatrix.ScaleVector(1), m_strokeStyle)
' Then draw the fill
D2DCanvas.canvas_renderTarget2D.DrawGeometry(m_fillTransformedGeometry, m_fillBrush, plaatdikte * _transformMatrix.ScaleVector(1), m_strokeStyle)
第二个想法是通过在原始折线-PathGeometry上调用 Widen()方法为笔划本身创建一个(略微加宽的)PathGeometry。
'define m_widenedPathGeometry (makes op the outline/stroke of this sheetmetal profile)
m_widenedPathGeometry = New PathGeometry(D2DCanvas.canvas_factory2D)
Using sink As SimplifiedGeometrySink = m_widenedPathGeometry.Open()
m_pathGeometry.Widen(0.2, sink)
sink.Close()
End Using
在绘制“填充”(两者都使用相同的StrokeStyle!)之前,这个加宽的几何体被绘制(考虑转换)为“笔划”:
' update m_transGeom based on m_widenedPathGeometry & the current transform matrix3x2,
m_transGeom = New TransformedGeometry(D2DCanvas.canvas_factory2D, m_widenedPathGeometry, Matrix3x2.Rotation(m_rotation, InsertPoint) * _transformMatrix)
' to draw the stroke of the Polyline
D2DCanvas.canvas_renderTarget2D.DrawGeometry(m_transGeom, m_strokeBrush, plaatdikte * _transformMatrix.ScaleVector(1), m_strokeStyle)
' update m_fillTransformedGeometry based on m_pathGeometry & the current transform matrix3x2,
m_fillTransformedGeometry = New TransformedGeometry(D2DCanvas.canvas_factory2D, m_pathGeometry, Matrix3x2.Rotation(m_rotation, InsertPoint) * _transformMatrix)
' to draw the fill of the PolyLine
D2DCanvas.canvas_renderTarget2D.DrawGeometry(m_fillTransformedGeometry, m_fillBrush, plaatdikte * _transformMatrix.ScaleVector(1), m_strokeStyle)
这会对End-Caps产生不良影响: (圆角,未在StrokeStyle中定义,或介于两者之间)
当我将已使用的StrokeStyle重新定义为具有“圆形”端盖时,此笔划/填充方法可正常工作:
但是'扁平'的封顶真的是我所追求的。
为什么会发生这种情况,或者我如何解决这个问题?
干杯!
答案 0 :(得分:0)
发现这里出了什么问题!
为可能遇到类似内容的其他人写下来。
在创建加宽的几何体时,我添加了'FigureEnd'属性设置为'Open',这可以防止在自身上创建“闭环”的几何体,从而导致这些伪影。
{{1}}