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

Posted

技术标签:

【中文标题】如何使用 Skia Sharp 添加矩形并将填充颜色和描边颜色应用于该对象?【英文标题】:How to add rect using Skia Sharp and apply both fill color and stroke color to that object? 【发布时间】:2017-02-17 11:31:32 【问题描述】:

如何使用 Skia Sharp 添加矩形或任何形状并将填充颜色和描边颜色应用于 ios 中的该对象

【问题讨论】:

【参考方案1】:

要同时绘制填充和描边,您必须执行两个绘制操作:

// 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 绘图之间的区别吗?看起来两者都很相似。 没有真正的区别。但 SkiaSharp 的优势在于代码在大多数平台上 100% 可重用——服务器到移动设备,Windows 到 linux。

以上是关于如何使用 Skia Sharp 添加矩形并将填充颜色和描边颜色应用于该对象?的主要内容,如果未能解决你的问题,请参考以下文章