Skip to content

Commit

Permalink
[Controls] Allow use TBitmap.Assign from graphics decoded by Skia cod…
Browse files Browse the repository at this point in the history
…ecs on Vcl

Ecample:
```pascal
  var LPicture := TPicture.Create;
  try
    LPicture.LoadFromFile('a.webp');
    ABitmap.Assign(LPicture.Graphic);
  finally
    LPicture.Free;
  end;
```

Co-Authored-By: Paulo César Botelho Barbosa <16469061+paulocesarbot@users.noreply.github.com>
  • Loading branch information
viniciusfbb and paulocesarbot committed Nov 23, 2024
1 parent 1c6b1eb commit 50c3d5a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Source/VCL/Vcl.Skia.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,7 @@ TSkGraphic = class(TGraphic)
FImage: ISkImage;
function GetBuffer(const ASize: TSize; const AOpacity: Byte): TBitmap;
strict protected
procedure AssignTo(ADest: TPersistent); override;
procedure Changed(ASender: TObject); override;
procedure Draw(ACanvas: TCanvas; const ARect: TRect); override;
procedure DrawTransparent(ACanvas: TCanvas; const ARect: TRect; AOpacity: Byte); override;
Expand Down Expand Up @@ -6326,6 +6327,22 @@ class function TSkGraphic.CanLoadFromStream(AStream: TStream): Boolean;
end;
{$ENDIF}

procedure TSkGraphic.AssignTo(ADest: TPersistent);
begin
if ADest is TBitmap then
begin
TBitmap(ADest).SetSize(Width, Height);
if FImage <> nil then
TBitmap(ADest).SkiaDraw(
procedure(const ACanvas: ISkCanvas)
begin
ACanvas.DrawImage(FImage, 0, 0);
end);
end
else
inherited;
end;

procedure TSkGraphic.Changed(ASender: TObject);
begin
FreeAndNil(FBuffer);
Expand Down

0 comments on commit 50c3d5a

Please sign in to comment.