MeasureText SkiaSharp vs WinForms

109 Views Asked by At

I need to measure text height and width using SkiaSharp. This is my SkiaSharp code:

        SKPaint p = new SKPaint
        {
            Typeface = font.Typeface,
            TextSize = font.Size
        }
        var textBounds = new SKRect(boxSize.Width, boxSize.Height, 0, 0);
        p.MeasureText(text, ref textBounds);

and my old code:

System.Windows.Forms.TextRenderer.MeasureText(text, font, boxSize);

SkiaSharp code returns width:5, height:6 MeasureText code return width:15, height:17 for same font, text and boxSize

AFAIK MeasureText uses DPI machine DPI and SkiaSharp defaults to 72 but I have no idea what to do with this information.

  1. How can I write my SkiaSharp code to return same values as MeasureText?
  2. How can I check what DPI value TextRenderer.MeasureText used?
0

There are 0 best solutions below