如何使用Skia Sharp添加矩形并对该对象应用填充颜色和描边颜色?

12

如何在iOS中使用Skia Sharp添加矩形或任何形状,并对该对象应用填充颜色和描边颜色

1个回答

24

为了同时绘制填充和描边,您需要执行两个涂料操作:

// the rectangle
var rect = SKRect.Create(10, 10, 100, 100);

// the brush (fill with blue)
var paint = new SKPaint {
    Style = SKPaintStyle.Fill,
    Color = SKColors.Blue
};

// draw fill
canvas.DrawRect(rect, paint);

// change the brush (stroke with red)
paint.Style = SKPaintStyle.Stroke;
paint.Color = SKColors.Red;

// draw stroke
canvas.DrawRect(rect, paint);

感谢 @Matthew 的帮助,你能帮我找出使用 UIView 和 SkiaSharp 作图的区别吗?它们似乎很相似。 - Devaraj
没有实质性的区别。但是 SkiaSharp 的优点在于代码可以在大多数平台上进行100%的重用 - 从服务器到移动设备,从 Windows 到 Linux。 - Matthew

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接