LoadImg

Syntax

Image = LoadImg(Path$, Flags=0)

Description

Loads an image from a file into a new ProGUI image object. Supports common image formats like PNG, JPEG, BMP, and ICO. For ICO files containing multiple sizes, it loads all sizes and automatically associates them as variants (ImgAddSize) with the returned base image handle (which corresponds to the smallest size found in the ICO).

Parameters

Path$
The file path to the image file to load.

Flags (optional)
Flags to modify loading behavior. Currently defined flags:

#PG_Img_SnapToSize : (See ImgSetProperty) Sets the snap-to-size property on the loaded image handle immediately.

Return Value

Returns a handle to the newly created ProGUI image object if successful, or #Null if the image could not be loaded (e.g., file not found, invalid format, memory error).

Remarks

The returned image handle should be freed using FreeImg() when no longer needed. The function attempts to load the image using the underlying graphics subsystem's capabilities. ICO loading includes parsing multiple icon dimensions and automatically creating the main handle and alternate size variants. The default interpolation mode for loaded images is #PG_InterpolationMode_Linear.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Load a PNG image
MyPNG = LoadImg("images/my_graphic.png")
If MyPNG
  Debug "PNG loaded successfully. Width: " + ImgGetWidth(MyPNG)
  FreeImg(MyPNG)
Else
  Debug "Failed to load my_graphic.png"
EndIf

; Load an ICO file (potentially containing multiple sizes)
MyIcon = LoadImg("icons/app_icon.ico")
If MyIcon
  Debug "ICO loaded successfully. Base Width: " + ImgGetWidth(MyIcon)
  ; ProGUI automatically handles the other sizes within MyIcon handle
  FreeImg(MyIcon)
Else
  Debug "Failed to load app_icon.ico"
EndIf

StopProGUI()

See Also

CreateImg, FreeImg, ImgAddSize, ImgSetProperty

Supported OS

Windows, Linux