Search code examples
c#skiasharp

Need to obtain HorizontalResolution and VerticalResolution in SkiaSharp


I am trying to scale a picture by SkiaSharp and got the following code:

Stream pictureStream = GetPictureStream(filename);
using var skImageStream = new SKManagedStream(pictureStream);
using var skPicture = SKPicture.Deserialize(skImageStream);                                     
var width = skPicture.CullRect.Width / skPicture.HorizontalResolution * 72;
var height = skPicture.CullRect.Height / skPicture.VerticalResolution * 72;

I am looking for a way to obtain HorizontalResolution and VerticalResolution from skPicture or anything else in SkiaSharp but I failed to find a solution. SKPicture, SKCanvas, and SKBitmap, do not have such a property.

Could you please suggest a solution for this problem?


Solution

  • This answer is per Maku's comment made above: SKPicture is just a recording of drawing commands, it's not an image until drawn. And resolution is just a metadata of images to indicate print size.