Recent

Author Topic: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.  (Read 10450 times)

freeman35

  • Jr. Member
  • **
  • Posts: 92
Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« on: September 15, 2014, 05:21:58 pm »
I need show small (75kb) avi in form, like a TAnimate. And crosscompile. Lazarus not support yhis, so I convert avi to gif, but I get this error in TImage, while try load gif file.
fpc, lazarus, bgra and lazpaint last SVN version on kubuntu x64

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #1 on: September 15, 2014, 09:56:35 pm »
The animation contained in a TBGRAAnimatedGif cannot be played by putting it in a TImage. You can however use a TBGRAVirtualScreen, and a timer. In the timer event, you can check if the image needs to be updated with the property TimeUntilNextImageMs.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #2 on: September 16, 2014, 03:56:51 am »
Also you can use BGRASpriteAnimation
http://wiki.freepascal.org/BGRASpriteAnimation
and use
Code: [Select]
TBGRASpriteAnimation.AnimatedGifToSprite(Filename: string): TBGRABitmap;

freeman35

  • Jr. Member
  • **
  • Posts: 92
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #3 on: September 16, 2014, 10:27:53 am »
@007
Thank you, I found one bug in TBGRASpriteAnimation.AnimStatic
Code: [Select]
procedure TBGRASpriteAnimation.SetFAnimStatic(const AValue: boolean);
begin
  if FAnimStatic = AValue then
    Exit;
  FAnimStatic := AValue;

  if csDesigning in ComponentState then
    Exit;
  FAnimTimer.Enabled := AValue; // --> Not AValue Why If set to True then animation is stop ? :)
end;

and my suggestion
Code: [Select]
function TBGRASpriteAnimation.AnimatedGifToSprite(Filename: string): TBGRABitmap;
....
    TempBitmap.BlendImage(TempGif.Width * n, 0, TempGif.MemBitmap, boLinearBlend);
  end;
   FSpriteCount := TempGif.Count;// --> I added this line. TempGif.Count know better then me FSpriteCount
  TempGif.Free;

And Timer is work, and "AnimPosition" increase, but no bitmap showing? maybe "PositionChanged" notifyevent need give via param, positioned bitmap? or global property so I can get it and assign somewhere.
I need this avi in form, it will not change, just if form is show and meybe I will animate, so "bgra.AnimatedGifToSprite('~/Video/tes.gif');" not good solution for me. I want to store this gif in form. I wanna add my gif from OI "Sprite" property. When I open here on design time, load gif file, o can preview it in property editor, but when click ok then I get this error
"Cannot assign a TBGRAAnimatedGif to a TBitmap."


@circular
TImage is lazarus class, I'm not modified, Not looked in but my idea is property editor is override, so TImage.Picture popup that error. For TBGRAVirtualScreen suggestion, need looking for some demo and help, I didn't use before. Small code example sometime much more useful then one page help write. I'm still looking for
Thank you

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #4 on: September 16, 2014, 10:52:27 am »
Supposing you have a form with a BGRAVirtualScreen component and a Timer component with interval set to 15 milliseconds, here is the code in the form that displays a gif:

Code: [Select]
unit utestgif;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  BGRAVirtualScreen, BGRABitmapTypes, BGRAAnimatedGif, BGRABitmap;

type

  { TForm1 }

  TForm1 = class(TForm)
    BGRAVirtualScreen1: TBGRAVirtualScreen;
    Timer1: TTimer;
    procedure BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    gif : TBGRAAnimatedGif;
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  BGRAVirtualScreen1.Align := alClient;
  gif := TBGRAAnimatedGif.Create('lazarus_running.gif');
end;

procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
begin
  Bitmap.PutImage(0,0,gif.MemBitmap,dmDrawWithTransparency);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  gif.Free;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if gif.TimeUntilNextImageMs <= 0 then BGRAVirtualScreen1.DiscardBitmap;
end;

end.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #5 on: September 16, 2014, 12:27:07 pm »
@007
Thank you, I found one bug in TBGRASpriteAnimation.AnimStatic
Code: [Select]
procedure TBGRASpriteAnimation.SetFAnimStatic(const AValue: boolean);
begin
  if FAnimStatic = AValue then
    Exit;
  FAnimStatic := AValue;

  if csDesigning in ComponentState then
    Exit;
  FAnimTimer.Enabled := AValue; // --> Not AValue Why If set to True then animation is stop ? :)
end;

and my suggestion
Code: [Select]
function TBGRASpriteAnimation.AnimatedGifToSprite(Filename: string): TBGRABitmap;
....
    TempBitmap.BlendImage(TempGif.Width * n, 0, TempGif.MemBitmap, boLinearBlend);
  end;
   FSpriteCount := TempGif.Count;// --> I added this line. TempGif.Count know better then me FSpriteCount
  TempGif.Free;

And Timer is work, and "AnimPosition" increase, but no bitmap showing? maybe "PositionChanged" notifyevent need give via param, positioned bitmap? or global property so I can get it and assign somewhere.
I need this avi in form, it will not change, just if form is show and meybe I will animate, so "bgra.AnimatedGifToSprite('~/Video/tes.gif');" not good solution for me. I want to store this gif in form. I wanna add my gif from OI "Sprite" property. When I open here on design time, load gif file, o can preview it in property editor, but when click ok then I get this error
"Cannot assign a TBGRAAnimatedGif to a TBitmap."

If AnimStatic is True // animation stop
Timer.Enabled is False // timer stop

Yeah, in fact it just do the conversion and not assign the bitmap to the component. It should be outside the class... or fixed to assign it directly.

With the output bitmap do .SaveToFile and save it as sprite.png, then load it in the object inspector and set the num of frames.

When you have the converted bitmap, you can attach it in Sprite property, and it will be saved with your project resources.


Fixed on SVN of BGRA-Controls, now just do:
Code: [Select]
BGRASpriteAnimation1.AnimatedGifToSprite('image.gif');  and it does the job.

BTW you must set the speed in ms with AnimSpeed property.
« Last Edit: September 16, 2014, 01:13:10 pm by 007 »

freeman35

  • Jr. Member
  • **
  • Posts: 92
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #6 on: September 17, 2014, 11:20:28 am »
@007 Thank you, answer and added
I have to say some bug too sorry :(
When dblclick TBGRASpriteAnimation.Tile on OI then get this message and IDE crash and close.

Quote
Invalid floating point operation.
Press OK to ignore and risk data corruption.
Press Cancel to kill the program.

SpriteResampleMode -> rmFineResample
Try "Stretch" set to True from OI

Quote
Scanline: out of bounds.
Press OK to ignore and risk data corruption.
Press Cancel to kill the program.

Stretch -> True But Showed bitmap not strech, normal view on runtime gif file has problem, recreate it and work good now
AutoSize -> True But Showed bitmap normal size on runtime, what for I couldn't understand still
Center -> True, yes this is work centered bitmap

And question:
How to get painted or will painting Tbitmap, for example. maybe I need transparent, or effect  while painting

procedure TForm1.B_PositionChanged(Sender: TObject);
begin
  Image1.Picture.Assign(B_.Sprite);// or any code
end; 

Thank you
« Last Edit: September 17, 2014, 12:19:23 pm by freeman35 »

freeman35

  • Jr. Member
  • **
  • Posts: 92
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #7 on: September 17, 2014, 11:58:12 am »
@circular
Thank you so much, for example code, its so useful for me, and I'm sure for many people too.
Thank you

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #8 on: September 17, 2014, 03:39:38 pm »
@007 Thank you, answer and added
I have to say some bug too sorry :(
When dblclick TBGRASpriteAnimation.Tile on OI then get this message and IDE crash and close.

Quote
Invalid floating point operation.
Press OK to ignore and risk data corruption.
Press Cancel to kill the program.

SpriteResampleMode -> rmFineResample
Try "Stretch" set to True from OI

Quote
Scanline: out of bounds.
Press OK to ignore and risk data corruption.
Press Cancel to kill the program.

Stretch -> True But Showed bitmap not strech, normal view on runtime gif file has problem, recreate it and work good now
AutoSize -> True But Showed bitmap normal size on runtime, what for I couldn't understand still
Center -> True, yes this is work centered bitmap

And question:
How to get painted or will painting Tbitmap, for example. maybe I need transparent, or effect  while painting

procedure TForm1.B_PositionChanged(Sender: TObject);
begin
  Image1.Picture.Assign(B_.Sprite);// or any code
end; 

Thank you

autosize is not implemented

most issues on design time, i know, it was one of my first components and never finish writing it again

to paint use onredrawafter or onredrawbefore

freeman35

  • Jr. Member
  • **
  • Posts: 92
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #9 on: September 18, 2014, 10:36:45 am »
Code: [Select]
     { Public declarations }
+    procedure GifImageToSprite(Gif: TBGRAAnimatedGif);//FreeMan35 added
+    procedure LoadFromResourceName(Instance: THandle; const ResName: String);//FreeMan35 added
     procedure AnimatedGifToSprite(Filename: string);
I add two procedure and modified in "AnimatedGifToSprite"
Why I added: easy way for me, then modify designtime package and property editor :) I need store gif file in form, make resource is second way, but at this time been first way, not much important. But need "LoadFromResourceName" procedure, I added
"GifImageToSprite"  procedure for: TBGRAAnimatedGif class can sent in TBGRASpriteAnimation

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #10 on: September 18, 2014, 02:37:03 pm »
I can't apply the diff, if you already has the patched file upload it since there is no other change on it

freeman35

  • Jr. Member
  • **
  • Posts: 92
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #11 on: September 18, 2014, 04:18:31 pm »
I can't apply the diff, if you already has the patched file upload it since there is no other change on it
If you accept my changed, I'll try make patch file.

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #12 on: September 18, 2014, 05:55:23 pm »
I can't apply the diff, if you already has the patched file upload it since there is no other change on it
If you accept my changed, I'll try make patch file.

It's ok.

Edit: I've updated bgracontrols and added the modifications.
« Last Edit: September 18, 2014, 10:00:24 pm by 007 »

freeman35

  • Jr. Member
  • **
  • Posts: 92
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #13 on: September 19, 2014, 10:08:37 am »
Thank you so much, work fine now for me :)

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Cannot assign a TBGRAAnimatedGif to a TBGRAAnimatedGif.
« Reply #14 on: September 19, 2014, 01:43:45 pm »
Ok! If you can solve another bug in any control just tell us.

 

TinyPortal © 2005-2018