我正在使用skiasharp和xamarin表单创建自定义控件。我遇到的问题是,当我尝试在画布的左上角绘制文本时,我必须偏移y坐标以使文本在画布中呈现。我希望文本的x y与rect的x y处于同一位置。我想念什么?
使用Skiasharp.View.Forms-nuget v1.68.1关闭
谢谢!
protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
{
base.OnPaintSurface(args);
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear();
canvas.Save();
using var paint = new SKPaint {IsAntialias = true, Color = Color.Black.ToSKColor(), Style = SKPaintStyle.Stroke};
canvas.DrawRect(0, 0, info.Width, info.Height, paint);
canvas.DrawText("Off screen", 0, 0, paint);
canvas.DrawText("On screen", 0, 10, paint);
canvas.Restore();
}
答案 0 :(得分:2)
您可以将y坐标设置为SKPaint.FontSpacing
,这是推荐的行距。
canvas.DrawText("SKCanvasView Height and Width:", 0, paint.FontSpacing, paint);