Recent

Author Topic: Is there someway to include pictures in the exefile?  (Read 1202 times)

Robert William Blennerhed

  • Sr. Member
  • ****
  • Posts: 282
  • Love my Wife, My Kids and Lazarus/Freepascal.
    • Spelstatistiken.se
Is there someway to include pictures in the exefile?
« on: August 06, 2018, 03:09:43 am »
In Android java, my Pictures for my Aura Migraine app is included in the apk file.
Is there a way to include Pictures in the Lazarus/Freepascal exefile?
Or do i have to send them in a mapp with the aura migraine exefile?
Sincerely
Bob :-[
« Last Edit: August 06, 2018, 03:13:31 am by R.Blennerhed »
%

Handoko

  • Hero Member
  • *****
  • Posts: 3773
  • My goal: build my own game engine using Lazarus
Re: Is there someway to include pictures in the exefile?
« Reply #1 on: August 06, 2018, 04:23:53 am »
Yes, you can include images into the exe file.

Try this:
01. Lazarus main menu > Project > Project Options
02. Project Options > Resources > Add


Then this is the the example code to load the image:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, Forms, Controls, Graphics, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Image1: TImage;
  16.     procedure FormCreate(Sender: TObject);
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25.  
  26. { TForm1 }
  27.  
  28. procedure TForm1.FormCreate(Sender: TObject);
  29. var
  30.   Stream: TResourceStream;
  31. begin
  32.   // Get the background image
  33.   Stream := TResourceStream.Create(HInstance, 'IMG', RT_RCDATA);
  34.   Image1.Picture.LoadFromStream(Stream);
  35.   Stream.Free;
  36. end;
  37.  
  38. end.

You can download the zip file for testing.

The documentation about Lazarus Resources:
http://wiki.freepascal.org/Lazarus_Resources
« Last Edit: August 06, 2018, 08:31:53 am by Handoko »

Robert William Blennerhed

  • Sr. Member
  • ****
  • Posts: 282
  • Love my Wife, My Kids and Lazarus/Freepascal.
    • Spelstatistiken.se
Re: Is there someway to include pictures in the exefile?
« Reply #2 on: August 10, 2018, 01:54:27 am »
Great :) :) :)
Thanks Handoko.
%

 

TinyPortal © 2005-2018