GithubHelp home page GithubHelp logo

SkLottieAnimation raises "Invalid Bitmap" when I want to flip horizontal (not roteate even thoug rotating raisies the same). about skia4delphi HOT 4 CLOSED

skia4delphi avatar skia4delphi commented on July 26, 2024
SkLottieAnimation raises "Invalid Bitmap" when I want to flip horizontal (not roteate even thoug rotating raisies the same).

from skia4delphi.

Comments (4)

Darkster1 avatar Darkster1 commented on July 26, 2024 1

Thanks, I understand but this will help me for sure :)

from skia4delphi.

viniciusfbb avatar viniciusfbb commented on July 26, 2024

Hi @Darkster1

This happens when trying to render a bitmap with no size (width or height zero) by calling TBitmap.SkiaDraw. I will remove this exception. For now try to avoid these zero-size renderings.

from skia4delphi.

Darkster1 avatar Darkster1 commented on July 26, 2024

I actually don't try to render zero size (that's maybe what happens) but what I want is render it horizontally flipped. Is there any other possible way doing this? with a LottieAnimation? like I have a file which displayes some people walking from left to right, I just want them (including background) to walk to the left when onTouch is fired.
So if you could implement something like that? would be great.

from skia4delphi.

viniciusfbb avatar viniciusfbb commented on July 26, 2024

@Darkster1 Ok, let's skip the "'Invalid Bitmap' raises" and focus on your problem which is the horizontal flip effect.

I made a small example adding the FlipAngle property to TSkSkottieAnimation:

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  System.Math, System.Math.Vectors, FMX.Types, FMX.Controls, FMX.Forms, 
  FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, Skia, Skia.FMX;

type
  TSkLottieAnimation = class(Skia.FMX.TSkLottieAnimation)
  strict private
    FFlipAngle: Single;
    procedure SetFlipAngle(const AValue: Single);
  strict protected
    procedure RenderFrame(const ACanvas: ISkCanvas; const ADest: TRectF; const AProgress: Double; const AOpacity: Single); override;
  public
    property FlipAngle: Single read FFlipAngle write SetFlipAngle;
  end;

  TForm1 = class(TForm)
    SkLottieAnimation1: TSkLottieAnimation;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

{ TSkLottieAnimation }

procedure TSkLottieAnimation.RenderFrame(const ACanvas: ISkCanvas;
  const ADest: TRectF; const AProgress: Double; const AOpacity: Single);
var
  LRotation: Single;
begin
  LRotation := Sin(DegToRad((FFlipAngle + 180) / 2));
  ACanvas.Save;
  ACanvas.Translate((1 - LRotation) * (ADest.Width / 2), 0);
  ACanvas.Scale(LRotation, 1);
  inherited;
  ACanvas.Restore;
end;

procedure TSkLottieAnimation.SetFlipAngle(const AValue: Single);
begin
  if not SameValue(FFlipAngle, AValue, TEpsilon.Angle) then
  begin
    FFlipAngle := AValue;
    Redraw;
  end;
end;

end.

See the result:

21.11.2021_16.30.37_REC.mp4

To make an animation with this new property, you can use the TFloatAnimation for example...
I will not add this property to the official TSkSkottieAnimation as it is a property for a very specific situation. And the idea is to keep everything summarized and simple.

Best regards Vinícius F.

from skia4delphi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.