Created
January 30, 2025 21:51
-
-
Save viniciusfbb/1848fa4999348e129b3223bd3adff2ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
program SkiaBlur2; | |
uses | |
System.StartUpCopy, | |
FMX.Forms, | |
FMX.Skia, | |
Unit1 in 'Unit1.pas' {Form1}; | |
{$R *.res} | |
begin | |
GlobalUseSkia := True; | |
Application.Initialize; | |
Application.CreateForm(TForm1, Form1); | |
Application.Run; | |
end. |
This file contains hidden or 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
unit Unit1; | |
interface | |
uses | |
System.SysUtils, System.Types, System.UITypes, System.Classes, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics; | |
type | |
TForm1 = class(TForm) | |
procedure FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
Form1: TForm1; | |
implementation | |
{$R *.fmx} | |
uses | |
System.Skia, FMX.Skia.Canvas; | |
procedure TForm1.FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); | |
begin | |
var LSkiaCanvas := TSkCanvasCustom(Canvas).Canvas; | |
// Draw background image | |
var LImage := TSkImage.MakeFromEncodedFile('C:\skia4delphi\skia4delphi\Samples\Demo\Assets\wolf.webp'); | |
if LImage <> nil then | |
LSkiaCanvas.DrawImageRect(LImage, TRectF.Create(0, 0, LImage.Width, LImage.Height).FitInto(ClientRect)); | |
// Draw circle | |
var LPaint: ISkPaint := TSkPaint.Create; | |
LPaint.Color := TAlphaColors.Red; // Cor do círculo | |
LPaint.AntiAlias := True; // Suaviza as bordas do círculo | |
LSkiaCanvas.DrawCircle(TPointF.Create(200, 150), 80, LPaint); | |
// Draw blur region | |
var LBlurRegion := TRectF.Create(200, 200, 500, 500); | |
LSkiaCanvas.Save; | |
try | |
LSkiaCanvas.ClipRect(LBlurRegion); | |
// SaveLayer with InitWithPrevious will paint everything drawed until now, | |
// using the image filter informed (blur on this case). | |
LSkiaCanvas.SaveLayer(nil, TSkImageFilter.MakeBlur(20, 20, nil, TSkTileMode.Decal), [TSkSaveLayerFlag.InitWithPrevious]); | |
try | |
// You can add more content here but it will not be blurred | |
finally | |
LSkiaCanvas.Restore; | |
end; | |
finally | |
LSkiaCanvas.Restore; | |
end; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment