Author Topic: Using BASIMAGE to embed images in InForm EXEs  (Read 281 times)

Offline JohnJames

  • Newbie
  • Posts: 7
Using BASIMAGE to embed images in InForm EXEs
« on: May 29, 2020, 09:07:32 AM »
Loving InForm. So good.

Placing an image is done by a link. If the EXE is run on another PC, that image path is lost and the EXE runs with a 'Missing Image' link error in its placeholder. In other words, the images are not embedded within the EXE.

Using 'BASIMAGE' in the QB64 code seems to be a possible way. It works perfectly in a separate QB64-only program but, in a QB64 program generated using InForm, it just doesn't work. Something to do with InForm constantly refreshing its canvas at run time 30 times a second?

Thanks,
John.


Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2116
  • LET IT = BE
    • QB64.org
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #1 on: May 29, 2020, 10:20:38 AM »
Hello, there.

I actually use a variant of BASIMAGE I had come up with before Dav dropped his official solution, so it is possible.

Since you won't be loading the image with the default method, there's a bit of a hack involved to get it working.

Say you have a control named PictureBox1 and  you want to place an image you loaded using BASIMAGE, so you already have a valid image handle called img&, and you know beforehand your image is 16x16 pixels:

Code: QB64: [Select]
  1.     Control(PictureBox1).HelperCanvas = _NEWIMAGE(16, 16, 32)
  2.     _PUTIMAGE (0, 0), img&, Control(PictureBox1).HelperCanvas

Let me know if it works for you. That's how InForm has built-in images without external files too.

Quote
Loving InForm. So good.
♥️

Thank you for your interest in QB64+InForm.

Offline JohnJames

  • Newbie
  • Posts: 7
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #2 on: May 29, 2020, 11:50:46 AM »
Thank you Fellippe. No, it doesn't seem to work, but probably me.

I am hacking the .frm code. Correct?

Code: QB64: [Select]
  1.     __UI_NewID = __UI_NewControl(__UI_Type_PictureBox, "PictureBox3", 400, 108, 410, 10, 0)
  2.     __UI_RegisterResult = 0
  3.     Control(PictureBox3).HelperCanvas = _NEWIMAGE(200, 54, 32)
  4.     _PUTIMAGE (0, 0), myLogo&, Control(PictureBox3).HelperCanvas
  5.     Control(__UI_NewID).Align = __UI_Center
  6.     Control(__UI_NewID).VAlign = __UI_Middle
  7.     Control(__UI_NewID).BorderSize = 1
  8.  

No errors, but no image, either.

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2116
  • LET IT = BE
    • QB64.org
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #3 on: May 29, 2020, 11:53:28 AM »
Try doing it at OnLoad. Also, let me see the line you're calling BASIMAGE with, if you don't mind.

Offline JohnJames

  • Newbie
  • Posts: 7
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #4 on: May 29, 2020, 12:02:00 PM »
I'm calling it at the top of the program...

Code: QB64: [Select]
  1. $EXEICON:'rds.ico'
  2. myLogo& = BASIMAGE1&  'Load the image
  3.  
  4. ': Controls' IDs: ------------------------------------------------------------------
  5.  
[...snip]





Offline JohnJames

  • Newbie
  • Posts: 7
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #5 on: May 29, 2020, 12:07:47 PM »
I receive an Illegal Function Call if I move the statement to OnLoad

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2116
  • LET IT = BE
    • QB64.org
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #6 on: May 29, 2020, 12:08:36 PM »
make sure to make myLogo& available globally too:

Code: QB64: [Select]
  1. DIM SHARED myLogo&

Or bypass it all along. In SUB __UI_OnLoad:

Code: QB64: [Select]
  1. Control(PictureBox3).HelperCanvas = BASIMAGE1&

In this case you don't need to use _NEWIMAGE manually, since BASIMAGE will do it for you.
« Last Edit: May 29, 2020, 12:20:20 PM by FellippeHeitor »

Offline JohnJames

  • Newbie
  • Posts: 7
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #7 on: May 29, 2020, 12:29:16 PM »
Ayyyy! It works. Bypassing was easiest/best.

Thank you Fellippe. And thank you for sharing your incredible work.

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2116
  • LET IT = BE
    • QB64.org
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #8 on: May 29, 2020, 12:31:48 PM »
Glad to hear it's solved.

Thank you for your kind words, too!

Offline Qwerkey

  • Forum Resident
  • Posts: 704
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #9 on: May 30, 2020, 05:35:14 AM »
... your incredible work.

Yep, it is incredible what Fellippe does.  It's all hobby work (he has a job (if not more than one), and a young family).  I just do not know how he does it.  [But by now, he will be fed up with my plaudits].

Offline SpriggsySpriggs

  • Forum Regular
  • Posts: 153
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Using BASIMAGE to embed images in InForm EXEs
« Reply #10 on: June 02, 2020, 03:14:50 PM »
I made a program that utilizes Dav's BASFILE and BASIMAGE programs that he wrote. I combined them both into a program that I call BIN2INCLUDE. It generates a file that you $INCLUDE at the end of your program to use/create later. The PIC2MEM option uses Dav's code with some tweaks by me so that the program generates a function named after the encoded image so you can call the function as an image handle using that Control(ControlId).HelperCanvas picture control. It works pretty good. Here is the link to the program. It uses InForm as well. Enjoy!
https://github.com/SpriggsySpriggs/BIN2INCLUDE
An example of how to use it:
Code: QB64: [Select]
  1. Control(OpenBT).HelperCanvas = __opensmall&