相关疑难解决方法(0)

.NET GDI +:绘制带圆角的线条

给定一个点数组,可以很容易地根据这些点绘制一条线,例如使用GraphicsPath类.

例如,以下几点...

[0]: (0,0)
[1]: (100,0)
[2]: (0,100)
[3]: (100,100)
Run Code Online (Sandbox Code Playgroud)

...描述了一个类似于Z的线.

但是接下来是挑战; 我需要绘制半径为10像素的圆角.在角落,我指的是线条中不是起点或终点的点.在这种情况下,有两个角(0,100)(100,0).

我玩过beziers,曲线和弧线,其中一些可能解决方案 - 我自己还没有找到它,因为我必须能够处理所有角度绘制的线条,而不仅仅是水平线条或垂直线条.

设置LineJoin所述的Pen目的是Round不充分的,因为这仅示出了具有较宽的笔.


编辑:为了澄清,我很清楚GraphicsPath类的bezier,曲线和弧功能.我正在寻找一些关于构建可以采用任意数量的点的算法的更具体的建议,并将它们与圆角串在一起.


我把以下函数放在一起,它返回一个表示带圆角的线的路径.该功能使用了LengthenLine功能,可在此处找到.

protected GraphicsPath GetRoundedLine(PointF[] points, float cornerRadius)
{
  GraphicsPath path = new GraphicsPath();
  PointF previousEndPoint = PointF.Empty;
  for (int i = 1; i < points.Length; i++)
  {
    PointF startPoint = points[i - 1];
    PointF endPoint = points[i];

    if (i > 1)
    {
      // shorten start point and add …
Run Code Online (Sandbox Code Playgroud)

.net drawing gdi+ rounded-corners graphicspath

3
推荐指数
1
解决办法
4806
查看次数

标签 统计

.net ×1

drawing ×1

gdi+ ×1

graphicspath ×1

rounded-corners ×1