我可以渲染路径并用纯色笔划/填充它:
SKPaint green = new SKPaint
{
Style = SKPaintStyle.StrokeAndFill,
Color = SKColors.LimeGreen,
StrokeWidth = 1,
IsAntialias = true
};
canvas.Clear();
SKPath path = new SKPath();
// here I define my path
canvas.DrawPath(path, green);
但是,如果我想使用一个小PNG作为我的";纹理";对于笔划/填充而不是颜色?例如,如果我有一个绿色草地/草坪的小PNG文件,我想用这个PNG作为纹理填充路径?在旧的Xamarin.iOS世界里,这很简单。
使用SkiaSharp可以做到这一点吗?
我在https://social.msdn.microsoft.com/Forums/en-US/9647627e-029d-4b63-bfb6-a247deee1bef/is-there-a-way-to-hatch-fill-a-rectangle?forum=xamarinlibraries.
基本上你会做以下事情:
- 从图像文件创建SKBitmap
- 从SKBitmap创建SKShader
- 分配";着色器";SKPaint的属性设置为#2
示例:
// Load bitmap
string resourceID = "myImage.png";
Assembly assembly = GetType().GetTypeInfo().Assembly;
SKBitmap bitmap;
using (Stream stream = assembly.GetManifestResourceStream(resourceID))
{
bitmap = SKBitmap.Decode(stream);
}
// Create the SKShader
SKShader shader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat);
// Create SKPaint
SKPaint myPaint = new SKPaint
{
Style = SKPaintStyle.StrokeAndFill,
Shader = shader
};