Advertisement
JimMcKeeth

Skia4Delphi high quality image resize

Mar 23rd, 2025 (edited)
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.62 KB | Source Code | 0 0
  1. function ResizedImage(const AImage: ISkImage; const ANewWidth, ANewHeight: Integer; const Proportional: Boolean = True): ISkImage;
  2. var
  3.   LSurface: ISkSurface;
  4.   HScale, VScale: Single;
  5. begin
  6.   HScale := ANewWidth / AImage.Width;
  7.   VScale := ANewHeight / AImage.Height;
  8.   if Proportional then
  9.   begin
  10.     HScale := min(HScale, VScale);
  11.     VScale := HScale;
  12.   end;
  13.   LSurface := TSkSurface.MakeRaster(ANewWidth, ANewHeight);
  14.   LSurface.Canvas.Clear(TAlphaColors.Null);
  15.   LSurface.Canvas.Scale(HScale, VScale);
  16.   LSurface.Canvas.DrawImage(AImage, 0, 0, TSkSamplingOptions.High);
  17.   Result := LSurface.MakeImageSnapshot;
  18. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement