/// <summary> /// Calculates the size. /// </summary> /// <returns>The size.</returns> /// <param name="size">Size.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> public static SKSize CalcSize(SkiaSharp.SKSize size, double width, double height) { double w; double h; if (width <= 0 && height <= 0) { return(size); } else if (width <= 0) { h = height; w = height * (size.Width / size.Height); } else if (height <= 0) { w = width; h = width * (size.Height / size.Width); } else { w = width; h = height; } return(new SkiaSharp.SKSize((float)w, (float)h)); }
/// <summary> /// Calculates the scale. /// </summary> /// <returns>The scale.</returns> /// <param name="originalSize">Original size.</param> /// <param name="scaledSize">Scaled size.</param> /// <param name="screenScale">Screen scale.</param> public static Tuple <float, float> CalcScale(SkiaSharp.SKSize originalSize, SkiaSharp.SKSize scaledSize, float screenScale) { var sx = scaledSize.Width * screenScale / originalSize.Width; var sy = scaledSize.Height * screenScale / originalSize.Height; return(new Tuple <float, float>((float)sx, (float)sy)); }
public void Inflate(SKSize size) { Inflate(size.Width, size.Height); }
private SKRect AspectResize(SKSize size, bool fit) { if (size.Width == 0 || size.Height == 0 || Width == 0 || Height == 0) return SKRect.Create(MidX, MidY, 0, 0); float aspectWidth = size.Width; float aspectHeight = size.Height; float imgAspect = aspectWidth / aspectHeight; float fullRectAspect = Width / Height; bool compare = fit ? (fullRectAspect > imgAspect) : (fullRectAspect < imgAspect); if (compare) { aspectHeight = Height; aspectWidth = aspectHeight * imgAspect; } else { aspectWidth = Width; aspectHeight = aspectWidth / imgAspect; } float aspectLeft = MidX - (aspectWidth / 2f); float aspectTop = MidY - (aspectHeight / 2f); return SKRect.Create(aspectLeft, aspectTop, aspectWidth, aspectHeight); }
public SKRect AspectFill(SKSize size) => AspectResize(size, false);
public SKRect AspectFit(SKSize size) => AspectResize(size, true);
public static SKSize Subtract(SKSize sz1, SKSize sz2) => sz1 - sz2;
public static SKSize Add(SKSize sz1, SKSize sz2) => sz1 + sz2;
public static SKPoint Add(SKPoint pt, SKSize sz) => pt + sz;
public void DrawOval(SKPoint c, SKSize r, SKPaint paint) { DrawOval(c.X, c.Y, r.Width, r.Height, paint); }
public void DrawRoundRect(SKRect rect, SKSize r, SKPaint paint) { DrawRoundRect(rect, r.Width, r.Height, paint); }
public SKSvg(float pixelsPerInch, SKSize canvasSize) : base(pixelsPerInch, canvasSize) { }
public SKSvg(SKSize canvasSize) : base(canvasSize) { }
public static SKRect Create(SKPoint location, SKSize size) { return SKRect.Create(location.X, location.Y, size.Width, size.Height); }
public static SKPoint Subtract(SKPoint pt, SKSize sz) => pt - sz;
public static SKRect Create(SKSize size) { return SKRect.Create(SKPoint.Empty, size); }
public void Deflate(SKSize size) { Deflate(size.Width, size.Height); }