【问题标题】:SkiaSharp - how to create a hatch or dotted pattern on the filled space between curvesSkiaSharp - 如何在曲线之间的填充空间上创建阴影或虚线图案
【发布时间】:2021-09-01 22:26:21
【问题描述】:

在 SkiaSharp 中,我可以使用 SKPathFillType.EvenOdd 很好地填充两条曲线之间的空间。下面我展示了代码的简化摘录。 我的问题是如何为曲线之间的填充区域赋予某种模式?在这里我只能用颜色填充它并赋予它透明度。我有兴趣应用图案,例如影线或圆点。

感谢您的支持。

您好,

索林

SKPath path = new SKPath();
path.FillType = SKPathFillType.EvenOdd;

// start the first curve
path.MoveTo(....);
path.LineTo(....); // draw the curve and close it
....

path.AddCircle(....); // add a second curve as a circle

SKPaint paint = new SKPaint(new SKFont(SKTypeface.Default)) {
                IsAntialias = true,
                Style = SKPaintStyle.Fill,
                Color = SKColors.Blue.WithAlpha((byte)(0xFF * (1 - 0.5))),
                StrokeWidth = 1
            };

canvas.DrawPath(path, paint);

【问题讨论】:

    标签: skiasharp skia


    【解决方案1】:

    我设法用一个技巧解决了这个问题。 首先,我做了我上面写的一切,即

    canvas.DrawPath(path, paint)
    

    .... 将在两条曲线之间绘制一个填充区域,具有一定的透明度。 最重要的是(字面意思),我画了另一个图案:

    var hatch = new SKPath();
    hatch.AddCircle(0, 0, 1);
    var hatchPaint = new SKPaint {
       PathEffect = SKPathEffect.Create2DPath(SKMatrix.MakeScale(7, 7), hatch),
       Color = SKColors.RosyBrown,
       Style = SKPaintStyle.Stroke,
       StrokeWidth = 3
    };
    

    再说一遍:

     canvas.DrawPath(path, hatchPaint);
    

    这会在曲线之间的填充区域顶部绘制一个漂亮的填充图案。 注意:图案的大小是必不可少的 - 这里是 AddCircle(0, 0, 1),其中圆形射线为 1 个像素。如果你有一个更大的,填充图案会溢出填充区域,这不是你想要的。对我来说,这看起来像是 SKIA 中的一个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-19
      • 1970-01-01
      • 2021-03-02
      • 2012-10-15
      • 2021-11-26
      • 1970-01-01
      相关资源
      最近更新 更多