Including icons into code

Just starting out? Need help? Post your questions and find answers here.
Cezary
User
User
Posts: 89
Joined: Sun Feb 12, 2017 2:31 pm

Including icons into code

Post by Cezary »

Dear forum users,

is there some way to include all program icons into the code? I want to get only one executable file, without any additional icon files, but I can't find how to do that.
Thanks in advance for all suggestions.

Best regards
User avatar
Bisonte
Addict
Addict
Posts: 1233
Joined: Tue Oct 09, 2007 2:15 am

Re: Including icons into code

Post by Bisonte »

Code: Select all

DataSection
MyIcon:
IncludeBinary "MyIconFile.ico"
EndDataSection

CatchImage(#Icon, ?MyIcon)
Work with all images, with ImagePlugin ... like UsePngImageDecoder()...
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
Cezary
User
User
Posts: 89
Joined: Sun Feb 12, 2017 2:31 pm

Re: Including icons into code

Post by Cezary »

You're great!
Thank you.
Cezary
User
User
Posts: 89
Joined: Sun Feb 12, 2017 2:31 pm

Re: Including icons into code

Post by Cezary »

Yet another problem:
if I use:

Code: Select all

  ButtonImageGadget(#BtnIdManHdec,
                    ScaleDPIx(20), ScaleDPIy(19),
                    ScaleDPIx(20), ScaleDPIy(14),
                    ImageID(LoadImage(#PB_Any, "ICO/arrow_left.png")))
everything is ok,
but in this case:

Code: Select all

  ButtonImageGadget(#BtnIdManHdec,
                    ScaleDPIx(20), ScaleDPIy(19),
                    ScaleDPIx(20), ScaleDPIy(14),
                    CatchImage(0, ?ArrowLeftIco))
icon on the button disappears after first clickink on it.
What am I doing wrong?
I use PB 5.62 x64 on Linux.
User avatar
Bisonte
Addict
Addict
Posts: 1233
Joined: Tue Oct 09, 2007 2:15 am

Re: Including icons into code

Post by Bisonte »

Code: Select all

ImageID(CatchImage(0, ?ImageLabel))
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
Cezary
User
User
Posts: 89
Joined: Sun Feb 12, 2017 2:31 pm

Re: Including icons into code

Post by Cezary »

Thank you again, it works now, but with a little exeption:

Code: Select all

ImageID(CatchImage(#PB_Any, ?ImageLabel))
Thanks!
Iordanis
New User
New User
Posts: 4
Joined: Mon Feb 05, 2018 6:54 pm
Location: Thessaloniki , Greece

Re: Including icons into code

Post by Iordanis »

This is my first post. I decided to give PB a try over another competitive product and i created a small exe that opens a form and loads buttons (png files). The program runs but i need to clarify someηting. The code is the following:

Code: Select all

DataSection
  Archive:
  IncludeBinary "icons_48/Archive.png"
  Bank:
  IncludeBinary "icons_48/Bank.png"
  Bsman:
  IncludeBinary "icons_48/businessman.png"
  money:
  IncludeBinary "icons_48/money-bag.png"
  safebox:
  IncludeBinary "icons_48/safebox.png"
  cityscape:
  IncludeBinary "icons_48/cityscape.png"
 
EndDataSection

Procedure MyToolBar()
  
  UsePNGImageDecoder()

  ButtonImageGadget(0, 0, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?Archive)), #PB_Button_Toggle)

  ButtonImageGadget(1, 60, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?Bank)), #PB_Button_Toggle)

  ButtonImageGadget(2, 120, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?bsman)), #PB_Button_Toggle)

  ButtonImageGadget(3, 180, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?money-bag)), #PB_Button_Toggle)

  ButtonImageGadget(4, 240, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?safebox)), #PB_Button_Toggle)

  ButtonImageGadget(5, 300, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?cityscape)), #PB_Button_Toggle)

  

EndProcedure
My question is this.. in order to create an image DO i need to initialise the #image variable?
How does ButtonImageGadget work here if i havent loaded or created an image?

At some point it was complaining that i did not initialise an image and i do not remember what change i made and it stopped. The idea for all this is to include the image in the .app file.
"A good beginning is half the task"
Mac OSX 10.13.3 - PureBasic 5.62 (MacOS X - x64)
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Including icons into code

Post by citystate »

technically you have been creating the images with CatchImage() - this command loads an image from memory
ordinarily, I'd load all my images with specific image_numbers, and then assign them to the ButtonImageGadgets by number (this way you can reuse images easily without having to reload them - helps with memory usage too)
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Iordanis
New User
New User
Posts: 4
Joined: Mon Feb 05, 2018 6:54 pm
Location: Thessaloniki , Greece

Re: Including icons into code

Post by Iordanis »

Thank you. Your answer saved me hours of searching.
"A good beginning is half the task"
Mac OSX 10.13.3 - PureBasic 5.62 (MacOS X - x64)
Post Reply