Hi,
I'm trying to implement a drawing functionality in my Xamarin Forms app thanks to SkiaSharp.
It is working fine, I'm following the demos which work well.
My issue is that I set a bitmap in the canvas:
private async Task GetCanvasImage() { var imageBytes = await this.picManager.GetImagBytes("Photo_1f527ba5-33cc-4198-8280-aa579baf50fb"); var bitmap = SKBitmap.Decode(imageBytes); //bitmap.Resize(); bitmap.CopyTo(this.bitmap); }
The issue is that I want the picture to fit the screen borders.
But, I do not want to resize the image itself so that I keep the image quality and resolution.
Has anyone done that before ?
Thanks !
The trick is to scale the image during the draw, but preserving the aspect ratio.
I have a few convenience methods on SKRect
:
var pictureFrame = SKRect.Create(100, 100, 640, 480); var imageSize = myImage.Size; // eg: 100x200 var dest = pictureFrame.AspectFit(imageSize); // fit the size inside the rect // draw the image var paint = new SKPaint { FilterQuality = SKFilterQuality.High // high quality scaling }; canvas.DrawImage(myImage, dest, paint);
Hope this helps
Answers
The trick is to scale the image during the draw, but preserving the aspect ratio.
I have a few convenience methods on
SKRect
:Hope this helps
Excellent ! Once again, thank you very much !