评论上的链接目前已损坏。由于“samples”文件夹将来可能会再次更改路径,因此需要的人可以从https://github.com/mono/SkiaSharp页面开始探索。
有关使用 SkiaSharp 的更多信息,请参阅在线 API 文档以及有关使用skia sharp绘图的文章
对于需要实用快速入门的人来说,这里有一些示例:
获取 SKCanvas
using (var surface = SKSurface.Create (width: 640, height: 480, SKColorType.N_32, SKAlphaType.Premul)) {
SKCanvas myCanvas = surface.Canvas;
// Your drawing code goes here.
}
绘图文本
// clear the canvas / fill with white
canvas.DrawColor (SKColors.White);
// set up drawing tools
using (var paint = new SKPaint ()) {
paint.TextSize = 64.0f;
paint.IsAntialias = true;
paint.Color = new SKColor (0x42, 0x81, 0xA4);
paint.IsStroke = false;
// draw the text
canvas.DrawText ("Skia", 0.0f, 64.0f, paint);
}
绘制位图
Stream fileStream = File.OpenRead ("MyImage.png");
// clear the canvas / fill with white
canvas.DrawColor (SKColors.White);
// decode the bitmap from the stream
using (var stream = new SKManagedStream(fileStream))
using (var bitmap = SKBitmap.Decode(stream))
using (var paint = new SKPaint()) {
canvas.DrawBitmap(bitmap, SKRect.Create(Width, Height), paint);
}
使用图像过滤器绘图
Stream fileStream = File.OpenRead ("MyImage.png"); // open a stream to an image file
// clear the canvas / fill with white
canvas.DrawColor (SKColors.White);
// decode the bitmap from the stream
using (var stream = new SKManagedStream(fileStream))
using (var bitmap = SKBitmap.Decode(stream))
using (var paint = new SKPaint()) {
// create the image filter
using (var filter = SKImageFilter.CreateBlur(5, 5)) {
paint.ImageFilter = filter;
// draw the bitmap through the filter
canvas.DrawBitmap(bitmap, SKRect.Create(width, height), paint);
}
}