$EMBED: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "The '''$EMBED''' metacommand can embed any designated file (e.g. images, sounds, fonts and all other file types) into the compiled EXE file. You can roughly compare this to converting and placing a file's contents into DATA lines, but '''$EMBED''' obviously is much more convenient. {{PageSyntax}} : $EMBED:'{{Parameter|filename}}','{{Parameter|handle}}' {{PageParameters}} ; IMPORTANT : *Both parameters must be enclosed in single quotes and given as literal str...")
 
No edit summary
Line 3: Line 3:


{{PageSyntax}}
{{PageSyntax}}
: [[$EMBED]]:'{{Parameter|filename}}','{{Parameter|handle}}'
: [[$EMBED]]''':''''{{Parameter|filename}}'''',''''{{Parameter|handle}}'




{{PageParameters}}
{{PageParameters}}
; IMPORTANT
; IMPORTANT
: *Both parameters must be enclosed in single quotes and given as literal strings, variables cannot be used here.
:* Both parameters must be enclosed in single quotes and given as literal strings, variables cannot be used here.
: *The parameters will be checked while typing to ensure its validity, warnings (if any) will be displayed immediately in the IDE status area.
:* The parameters will be checked while typing to ensure its validity, warnings (if any) will be displayed immediately in the IDE status area.
* The {{Parameter|filename}} is the name of the file to embed, if required inclusive a full or relative path.
* The {{Parameter|filename}} is the name of the file to embed, if required inclusive a full or relative path.
* The {{Parameter|handle}} is a unique identifier beginning with a letter and only containing lower/upper case letters and/or numbers, it's used later in the [[_EMBEDDED$]] call to recall the embedded data.
* The {{Parameter|handle}} is a unique case sensitive identifier beginning with a letter and only containing lower/upper case letters and/or numbers, it's used later in the [[_EMBEDDED$]] call to recall the embedded data.
** You can compare this identifier to the line label in front of a [[DATA]] block, which is later used in a [[RESTORE]] call to set the [[READ]] pointer to exactly that [[DATA]] block.
** You can compare this identifier to the line label in front of a [[DATA]] block, which is later used in a [[RESTORE]] call to set the [[READ]] pointer to exactly that [[DATA]] block.


Line 21: Line 21:
* Embedded images, sounds or fonts can be passed directly to [[_LOADIMAGE]], [[_SNDOPEN]] or [[_LOADFONT]] respectively when using the ''memory load'' capabilities of these functions.
* Embedded images, sounds or fonts can be passed directly to [[_LOADIMAGE]], [[_SNDOPEN]] or [[_LOADFONT]] respectively when using the ''memory load'' capabilities of these functions.
* To recall the embedded file data use the [[_EMBEDDED$]] call with the very same {{Parameter|handle}} identifier which was used in the respective file's '''$EMBED''' line.
* To recall the embedded file data use the [[_EMBEDDED$]] call with the very same {{Parameter|handle}} identifier which was used in the respective file's '''$EMBED''' line.


{{PageAvailability}}
{{PageAvailability}}

Revision as of 00:15, 15 December 2023

The $EMBED metacommand can embed any designated file (e.g. images, sounds, fonts and all other file types) into the compiled EXE file. You can roughly compare this to converting and placing a file's contents into DATA lines, but $EMBED obviously is much more convenient.


Syntax

$EMBED:'filename','handle'


Parameters

IMPORTANT
  • Both parameters must be enclosed in single quotes and given as literal strings, variables cannot be used here.
  • The parameters will be checked while typing to ensure its validity, warnings (if any) will be displayed immediately in the IDE status area.
  • The filename is the name of the file to embed, if required inclusive a full or relative path.
  • The handle is a unique case sensitive identifier beginning with a letter and only containing lower/upper case letters and/or numbers, it's used later in the _EMBEDDED$ call to recall the embedded data.
    • You can compare this identifier to the line label in front of a DATA block, which is later used in a RESTORE call to set the READ pointer to exactly that DATA block.


Description

  • Embedding files can be useful to deliver a program inclusive all required assets in just one EXE file.
  • No more worries whether a user installs your program correctly and retains the required folder structure.
  • If required, you can write the files back to disk, i.e. it could serve as an simple installer or package manager.
  • Embedded images, sounds or fonts can be passed directly to _LOADIMAGE, _SNDOPEN or _LOADFONT respectively when using the memory load capabilities of these functions.
  • To recall the embedded file data use the _EMBEDDED$ call with the very same handle identifier which was used in the respective file's $EMBED line.


Availability


Examples

Example
Embeds two image files into the compiled EXE, then memory loads and displays it.
$EMBED:'source\peLogo.png','bigImg'
$EMBED:'source\qb64pe.png','smallImg'

SCREEN _NEWIMAGE(640, 480, 32)

bi& = _LOADIMAGE(_EMBEDDED$("bigImg"), 32, "memory")
si& = _LOADIMAGE(_EMBEDDED$("smallImg"), 32, "memory")

_PUTIMAGE (140, 180), bi&
_PUTIMAGE (410, 230), si&

_FREEIMAGE si&
_FREEIMAGE bi&

END
Code by RhoSigma


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link