This loads the specified image into the miniwindow, and remembers it by the nominated "image id". The image id is later used for drawing this image. Loading does not draw it, it simply reads it from disk ready for drawing later.
Also see below in the Lua notes for WindowLoadImageMemory which loads an image loaded into memory.
WindowName - the name of an existing miniwindow.
ImageId - the image id to be associated with this particular image.
FileName - the disk file to load the image from. It should be a BMP or PNG file, not a GIF, TIF or other file type. If the filename is the empty string (ie. "") then any existing image matching the ImageId is deleted.
For more information, see:
http://www.gammon.com.au/mushclient/mw_images.htm
If the loaded image is a PNG file, then it will have 24 bits per pixel if it does not have an alpha channel, and 32 bits per pixel if it has an alpha channel. You can use WindowImageInfo with selector 6 to find the number of bits per pixel of the loaded image.
From version 4.42 onwards, Lua also supports WindowLoadImageMemory which loads an image file loaded into a memory buffer.
In this case the third argument is the memory buffer, not the file name.
local f = assert (io.open ("sword.png", "rb"))
local image_data = f:read ("*a") -- read all of it
f:close () -- close it
WindowLoadImageMemory (win, "im", image_data) -- load image from memory
WindowDrawImage (win, "im", 20, 20, 0, 0, 1) -- draw it
For WindowLoadImageMemory only PNG files are supported, not BMP ones.
WindowLoadImageMemory also supports an optional fourth argument. If true, the blue channel is swapped with the alpha channel. Thus, code like below would load the image into "ima", and then show it in the miniwindow, showing only the alpha mask:
WindowLoadImageMemory (win, "ima", image_data, true)
WindowBlendImage (win, "ima", 0, 0, 0, 0, 59, 1)
Returns
eNoSuchWindow - no such miniwindow
eFileNotFound - specified file was not found
eUnableToLoadImage - can't load image - perhaps it is not a BMP or PNG file