Last active
September 18, 2022 03:18
-
-
Save viniciusfbb/5fea4dde189b55d6a0e062eb3491a9b6 to your computer and use it in GitHub Desktop.
Simple sample to drop shadow in image with 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
object Form2: TForm2 | |
Left = 0 | |
Top = 0 | |
Caption = 'Form2' | |
ClientHeight = 442 | |
ClientWidth = 628 | |
Color = clBtnFace | |
Font.Charset = DEFAULT_CHARSET | |
Font.Color = clWindowText | |
Font.Height = -12 | |
Font.Name = 'Segoe UI' | |
Font.Style = [] | |
TextHeight = 15 | |
object SkPaintBox1: TSkPaintBox | |
Left = 0 | |
Top = 0 | |
Width = 628 | |
Height = 442 | |
Align = alClient | |
OnDraw = SkPaintBox1Draw | |
ExplicitLeft = 296 | |
ExplicitTop = 216 | |
ExplicitWidth = 50 | |
ExplicitHeight = 50 | |
end | |
end |
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
unit Skia.Sample.DropShadow; | |
interface | |
uses | |
{ Delphi } | |
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, | |
System.Math, System.Types, System.UITypes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, | |
Vcl.Dialogs, | |
{ Skia } | |
Skia, Skia.Vcl; | |
type | |
TForm2 = class(TForm) | |
SkPaintBox1: TSkPaintBox; | |
procedure SkPaintBox1Draw(ASender: TObject; const ACanvas: ISkCanvas; | |
const ADest: TRectF; const AOpacity: Single); | |
public | |
{ Public declarations } | |
end; | |
var | |
Form2: TForm2; | |
implementation | |
{$R *.dfm} | |
procedure TForm2.SkPaintBox1Draw(ASender: TObject; const ACanvas: ISkCanvas; | |
const ADest: TRectF; const AOpacity: Single); | |
var | |
LPaint: ISkPaint; | |
LImage: ISkImage; | |
begin | |
LPaint := TSkPaint.Create; | |
LPaint.ImageFilter := TSkImageFilter.MakeDropShadow(6, 6, 4, 4, TAlphaColors.Black); | |
LImage := TSkImage.MakeFromEncodedFile('my_image.png'); | |
ACanvas.DrawImage(LImage, (ADest.Width - LImage.Width) / 2, (ADest.Height - LImage.Height) / 2, LPaint); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment