[英].NET draw line with outline using GDI+
我将 .NET 用于桌面应用程序。
我正在绘制一些带有大写开始和结束的线条以将它们用作箭头,使用 Graphics.DrawLine 和合适的笔,具有一些宽度(假设为 8px)。
现在我想要实现的是在其他颜色的线条中添加一个“轮廓”,宽度为 1 或 2 个像素。
我没有找到使用 GDI+ 执行此操作的选项(如果有此选项,也许它在“gdiplus.dll”中,我可以使用 dllimport 导入它)。
我的第一次尝试是先用更宽的笔绘制同一条线,但效果并不像您想象的那样适合箭头末端。
有什么想法吗?
更新:这是我第一次尝试绘制两条线时的图像,一条在另一条上:
这个答案有点晚了,但我有一个更好的,不完美但更好
用不同的偏移量绘制箭头 4 次,然后像这样在它上面绘制主要的箭头
Using bigArrow As New Drawing2D.AdjustableArrowCap(5, 5)
' Shadow
Using objPen As New Pen(Color.Black, 5)
objPen.CustomEndCap = bigArrow
gr.DrawLine(objPen, 50 - 2, 50 - 2, 100 - 2, 100 - 2)
gr.DrawLine(objPen, 50 + 2, 50 - 2, 100 + 2, 100 - 2)
gr.DrawLine(objPen, 50 + 2, 50 + 2, 100 + 2, 100 + 2)
gr.DrawLine(objPen, 50 - 2, 50 + 2, 100 - 2, 100 + 2)
End Using
' Line
Using objPen As New Pen(Color.CornflowerBlue, 5)
objPen.CustomEndCap = bigArrow
gr.DrawLine(objPen, 50, 50, 100, 100)
End using
End Using
它错过了角落,但还不错
经过多次试验,我终于明白了
使用 GraphicsPath 和加宽命令,另一个技巧是加宽也将线加宽到它伸出端盖箭头的点,所以也在端盖上使用 WidthScale,然后只减小端盖的大小
Using bigArrow As New Drawing2D.AdjustableArrowCap(3, 3)
bigArrow.WidthScale = 1.5
Using objPen As New Pen(Color.Black, 10)
objPen.CustomEndCap = bigArrow
Using objPath As New Drawing2D.GraphicsPath
objPath.AddLine(50, 50, 100, 100)
Using objWidenPen As New Pen(Color.Empty, 10)
objWidenPen.CustomEndCap = bigArrow
objPath.Widen(objWidenPen)
End Using
gr.DrawPath(objPen, objPath)
End Using
End Using
Using objPen As New Pen(Color.CornflowerBlue, 10)
objPen.CustomEndCap = bigArrow
gr.DrawLine(objPen, 50, 50, 100, 100)
End Using
End Using
结果看起来好多了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.