Created
October 24, 2024 16:46
-
-
Save viniciusfbb/01d12c9c2921d68da1e5a77e26d5f5f3 to your computer and use it in GitHub Desktop.
Skia4Delphi blur example for FMX
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 SkiaBlur; | |
uses | |
System.StartUpCopy, | |
FMX.Forms, | |
FMX.Types, | |
FMX.Skia, | |
Unit4 in 'Unit4.pas' {Form4}; | |
{$R *.res} | |
begin | |
GlobalUseSkia := True; | |
GlobalUseSkiaRasterWhenAvailable := False; | |
GlobalUseVulkan := True; | |
GlobalUseMetal := True; | |
Application.Initialize; | |
Application.CreateForm(TForm4, Form4); | |
Application.Run; |
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 Unit4; | |
interface | |
uses | |
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, | |
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects; | |
type | |
TImage = class(FMX.Objects.TImage) | |
protected | |
procedure Paint; override; | |
end; | |
TForm4 = class(TForm) | |
Image1: TImage; | |
TrackBar1: TTrackBar; | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
Form4: TForm4; | |
implementation | |
{$R *.fmx} | |
uses | |
System.Skia, FMX.Skia.Canvas; | |
{ TImage } | |
procedure TImage.Paint; | |
begin | |
if Canvas is TSkCanvasCustom then | |
begin | |
var LPaint: ISkPaint := TSkPaint.Create; | |
LPaint.ImageFilter := TSkImageFilter.MakeBlur(Form4.TrackBar1.Value, Form4.TrackBar1.Value); | |
TSkCanvasCustom(Canvas).Canvas.SaveLayer(LPaint); | |
end; | |
try | |
inherited; | |
finally | |
if Canvas is TSkCanvasCustom then | |
TSkCanvasCustom(Canvas).Canvas.Restore; | |
end; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is possible to use TBlurEffect as well but the blur effect directly using skia api is faster and better (without limit for softness / sigma).