Recent

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

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
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 »
Rob

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • 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 W.B.

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

YiannisKam

  • Full Member
  • ***
  • Posts: 100
Re: Is there someway to include pictures in the exefile?
« Reply #3 on: September 20, 2022, 03:55:35 pm »
I've tried the above example but it doesn't work for me. First error said, identifier not found RT_RCDATA. I typed quotes around it and it worked. But now I got an exception: Resource "IMG" not found.

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Is there someway to include pictures in the exefile?
« Reply #4 on: September 20, 2022, 04:42:53 pm »
Add unit LCLType to "uses".

YiannisKam

  • Full Member
  • ***
  • Posts: 100
Re: Is there someway to include pictures in the exefile?
« Reply #5 on: September 20, 2022, 05:09:04 pm »
It still doesn't work. Same exception message.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2054
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Is there someway to include pictures in the exefile?
« Reply #6 on: September 20, 2022, 05:15:25 pm »
It still doesn't work. Same exception message.
Code: Pascal  [Select][+][-]
  1. Uses Types
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2054
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Is there someway to include pictures in the exefile?
« Reply #7 on: September 20, 2022, 05:17:35 pm »
or
Code: Pascal  [Select][+][-]
  1. Uses Windows
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

YiannisKam

  • Full Member
  • ***
  • Posts: 100
Re: Is there someway to include pictures in the exefile?
« Reply #8 on: September 20, 2022, 05:29:48 pm »
Sorry, neither of them work.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2054
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Is there someway to include pictures in the exefile?
« Reply #9 on: September 20, 2022, 05:34:05 pm »
Sorry, neither of them work.
Than add it on your own.
Code: Pascal  [Select][+][-]
  1. const
  2.    RT_RCDATA = MAKEINTRESOURCE(10);
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: Is there someway to include pictures in the exefile?
« Reply #10 on: September 20, 2022, 06:08:49 pm »
but the exe file will be big , maybe better you put it in DLL and link it to the exe

https://github.com/alas82/resource-in-dll.git

thanks

« Last Edit: September 20, 2022, 06:57:22 pm by alaa123456789 »

YiannisKam

  • Full Member
  • ***
  • Posts: 100
Re: Is there someway to include pictures in the exefile?
« Reply #11 on: September 20, 2022, 07:09:25 pm »
After a lot of trial and error, it worked. I only need LCLType. The problem was the quotes around RT_RCDATA which I typed in the first place in order to get rid of the identifier not found error. That was hard.
And I want to apologize because you told me the solution, but I am a beginner and even reading the documentation is somewhat hard for me.

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Is there someway to include pictures in the exefile?
« Reply #12 on: September 20, 2022, 07:57:33 pm »
And I want to apologize because you told me the solution, but I am a beginner and even reading the documentation is somewhat hard for me.
No reason to excuse. We all started this way. And the more errors you make the faster you'll progress.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: Is there someway to include pictures in the exefile?
« Reply #13 on: September 21, 2022, 09:26:21 am »
but the exe file will be big , maybe better you put it in DLL and link it to the exe

https://github.com/alas82/resource-in-dll.git

And what does that really achieve? You still have to provide the library and in total the size will be bigger than if you'd put the image into the executable, because of the additional overhead of the library file itself minus the resources.

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: Is there someway to include pictures in the exefile?
« Reply #14 on: September 22, 2022, 05:48:02 pm »
And what does that really achieve? You still have to provide the library and in total the size will be bigger than if you'd put the image into the executable, because of the additional overhead of the library file itself minus the resources.
what you do then if you have software of 100 picture for ex??


 

TinyPortal © 2005-2018