I use SkiaSharp
to draw some SKRect on a SKCanvas
. I'm trying to implement a "scale to fit and center" functionality for the drawing area. I used the following code to calculate the bounding box for all the SKRect
s.
private SKRect GetBoundingBox()
{
int xMin = AllRectangles.Min(s => (int)s.Left);
int yMin = AllRectangles.Min(s => (int)s.Top);
int xMax = AllRectangles.Max(s => (int)s.Right);
int yMax = AllRectangles.Max(s => (int)s.Bottom);
SKRect result = new SKRect(xMin, yMin, xMax, yMax);
return result;
}
Now I want to translate the SKMatrix
used during PaintSurface to center the bounding box (with all the items in it) and scale the bounding box to fit the SKCanvasView
. I have a GIF which shows the Navigator View in Photoshop, doing what I'm trying to build.