Recent

Author Topic: Load 3 pictures into memory?[SOLVED]  (Read 1887 times)

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Load 3 pictures into memory?[SOLVED]
« on: July 09, 2018, 12:40:07 am »
Hi Pascal friends.
I should be happy to know, howto load 3 Pictures into memory
and then be able to use them as image1, image2, image3, to call them.
Is there anyone who have knowledge about this?

Thanks in advance
Bob
« Last Edit: July 09, 2018, 02:23:12 am by R.Blennerhed »
Rob

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Load 3 pictures into memory, variables?
« Reply #1 on: July 09, 2018, 12:47:42 am »
You can assign picture to TImage at design-time in Object Inspector (property Image.Picture) or at run-time:
Code: Pascal  [Select][+][-]
  1. Image1.Picture.LoadFromFile('/path/to/your/picture');
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Load 3 pictures into memory, variables?
« Reply #2 on: July 09, 2018, 01:10:01 am »
Thanks Blaazen for the Quick answer.
I need to load 3 Pictures and animate them with sleep just like this. But it won't work!
a:=0;
repeat
inc(a);
image1.show;
sleep(50);
image2.show;
sleep(50);
image3.show;
sleep(50);
until a=100;
Rob

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Load 3 pictures into memory, variables?
« Reply #3 on: July 09, 2018, 01:45:26 am »
I would use TPaintBox and TTimer instead of TImage and sleep().

I tested with *.png images so code looks like this:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3.  
  4. interface
  5.  
  6. uses
  7.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   { TForm1 }
  11.   TForm1 = class(TForm)
  12.     Button1: TButton;
  13.     PaintBox1: TPaintBox;
  14.     Timer1: TTimer;
  15.     procedure BitBtn1Click(Sender: TObject);
  16.     procedure FormDestroy(Sender: TObject);
  17.     procedure PaintBox1Paint(Sender: TObject);
  18.     procedure Timer1Timer(Sender: TObject);
  19.   private
  20.  
  21.   public
  22.     PNG1, PNG2, PNG3: TPortableNetworkGraphic;
  23.     Counter: Integer;
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.BitBtn1Click(Sender: TObject);
  36. begin
  37.   PNG1:=TPortableNetworkGraphic.Create;
  38.   PNG2:=TPortableNetworkGraphic.Create;
  39.   PNG3:=TPortableNetworkGraphic.Create;
  40.   PNG1.LoadFromFile('/path/to/your/picture1');
  41.   PNG2.LoadFromFile('/path/to/your/picture2');
  42.   PNG3.LoadFromFile('/path/to/your/picture3');
  43.   Timer1.Enabled:=True;
  44. end;
  45.  
  46. procedure TForm1.FormDestroy(Sender: TObject);
  47. begin
  48.   PNG1.Free;
  49.   PNG2.Free;
  50.   PNG3.Free;
  51. end;
  52.  
  53. procedure TForm1.PaintBox1Paint(Sender: TObject);
  54. begin
  55.   case Counter mod 3 of
  56.     0: PaintBox1.Canvas.Draw(0, 0, PNG1);
  57.     1: PaintBox1.Canvas.Draw(0, 0, PNG2);
  58.     2: PaintBox1.Canvas.Draw(0, 0, PNG3);
  59.   end;
  60. end;
  61.  
  62. procedure TForm1.Timer1Timer(Sender: TObject);
  63. begin
  64.   inc(Counter);
  65.   PaintBox1.Invalidate;
  66. end;
  67.  
  68. end.
Timer1 is designed with Enabled:=False and with requested Interval.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Load 3 pictures into memory, variables?
« Reply #4 on: July 09, 2018, 01:58:48 am »
The code looks really nice. Thanks for code.
I will check this immediately.
Best regards
Bob
Rob

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Load 3 pictures into memory, variables?
« Reply #5 on: July 09, 2018, 02:22:32 am »
Thank You, Thank You, Thank You very very very mutch. This is exactly the code i was hoping for.

You are very skill and in my heart, You are a real Hero Member.

Can I use the code in my program/app and also, i will certantly give You credit, if You wish?

Best regards and take care.

Robert from Sweden
Rob

 

TinyPortal © 2005-2018