小编Jak*_*fer的帖子

SkiaSharp 剪切路径

我正在使用 System.Drawing 进行一些图像编辑,现在将所有内容移植到 SkiaSharp 以便在 Linux / .NET Core 上使用它。一切工作正常,除了我还没有找到一种以编程方式为图像提供圆角的方法。

我编写了一些代码,这些代码依赖于以圆形形式绘制路径,然后尝试将路径的外部着色为透明。但这不起作用,因为看起来有多个层,并且使上层的部分透明并不会使图像的整个区域(所有层)透明。这是我的代码:

public static SKBitmap MakeImageRound(SKBitmap image)
{
    SKBitmap finishedImage = new SKBitmap(image.Width, image.Height);

    using (SKCanvas canvas = new SKCanvas(finishedImage))
    {
       canvas.Clear(SKColors.Transparent);
       canvas.DrawBitmap(image, new SKPoint(0, 0));
       SKPath path = new SKPath();
       path.AddCircle(image.Width / 2, image.Height / 2, image.Width / 2 - 1f);
       path.FillType = SKPathFillType.InverseEvenOdd;
       path.Close();
       canvas.DrawPath(path, new SKPaint {Color = SKColors.Transparent, Style = SKPaintStyle.Fill });
       canvas.ResetMatrix();              
       return finishedImage;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果这是错误的代码,我很抱歉,这是我第一次使用 C# 进行图像编辑,因此我也是 SkiaSharp 的绝对初学者。我修改了从这里获得的 System.Drawing 代码。

我还看了 …

.net c# .net-core skiasharp

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

标签 统计

.net ×1

.net-core ×1

c# ×1

skiasharp ×1