I draw line using SkiaSharp
as below, on an <Image>
, it works fine. But when I tested in another device with another resolution, the drawing is not on the same location I saw on my first device.
How can draw using SkiaSharp
in a device-independent manner.
private void canvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args)
{
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear();
if (isFromSearchPage)
{
SKPaint thickLinePaint = new SKPaint
{
Style = SKPaintStyle.Stroke, //.StrokeAndFill,
Color = SKColors.Yellow.WithAlpha(0x60),
StrokeWidth = 120//15
};
int startingLine = GetFirstLineNo();//1;//26;
int lineInPage = 0;
if (CurrentLine >= startingLine)
{
lineInPage = CurrentLine - startingLine + 1;
}
int positionY = (int)SepratorTypeHeight.PageHeader + (lineInPage * (int)SepratorTypeHeight.LineSeparator);
thickLinePaint.StrokeCap = SKStrokeCap.Square;
canvas.DrawLine(150, positionY, 1300, positionY, thickLinePaint);
isFromSearchPage = false;
}
}