Created
November 7, 2022 17:41
-
-
Save viniciusfbb/0eb3d2dab0b7e4f78435bdcd44cc03ee to your computer and use it in GitHub Desktop.
Simple example resizing an image using Skia4Delphi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses | |
System.UITypes, Skia; | |
function GetResizedImage(const AImage: ISkImage; const ANewWidth, ANewHeight: Integer): ISkImage; | |
var | |
LSurface: ISkSurface; | |
begin | |
LSurface := TSkSurface.MakeRaster(ANewWidth, ANewHeight); | |
LSurface.Canvas.Clear(TAlphaColors.Null); | |
LSurface.Canvas.Scale(ANewWidth / AImage.Width, ANewHeight / AImage.Height); | |
LSurface.Canvas.DrawImage(AImage, 0, 0, TSkSamplingOptions.High); | |
Result := LSurface.MakeImageSnapshot; | |
end; | |
procedure TForm1.FormCreate(Sender: TObject); | |
var | |
LImage: ISkImage; | |
begin | |
LImage := TSkImage.MakeFromEncodedFile('a.png'); | |
LImage := GetResizedImage(LImage, 24, 24); | |
LImage.EncodeToFile('a.png', 100); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Спасибо за пример. Изменил код с сохранением соотношения сторон и прозрачным фоном вокруг