|
LoadImage | ||
LoadImage Filename$, ImageNumber, [Format =1] | ||
Parameters: Filename$ = The Filename and path of the image you wish to load ImageNumber = The Image Number where you wish to store/reference this picture data [Format =1] = Format of image to create, Format defaults to Video (1), use 2 for FX and 8 for AFX |
||
Returns: NONE | ||
LoadImage reads a picture file from disc into PlayBASICs image memory. You must provide this command with the full folder path and filename of the image you wish to load, as well as a free (not currently in use) image index. If you wish PlayBASIC to manage indexes for you, see LoadNewImage Image Format Parameter: PlayBASIC has various types of images, each one is suited for different uses. 1 = Video - Image is created in Video Memory 2 = FX - System Memory Image 8 = AFX - System Memory Image With Alpha Channel To learn more about images we highly recommend you read the CreateImage, Images & Sprites tutorials FACTS: * LoadImage supports various popular image formats including BMP, TGA JPEG, PNG as well PlayBASIC very own Image Format called PBI * Images loaded with LoadImage are stored in your computers Video memory by default (Mode 1). Use the Format parameter to select the select that format. The only exception to this is when loading JPG images, which will always default to video. * Images stored Video Memory are most suitable for fast static (no rotation or alpha) drawing. Video Images are drawn using your computers Video Card (GPU). Since the image data is stored in graphics memory, they can not withstand breaks in service from your operating system, such as, when the user presses ALT-TAB, or when the OS decides to hibernate while your program is running. If a break of service occurs, you should reload/recreate these images. * LoadImage does not change PlayBASIC current graphics output. So if you want to redirect drawing operations onto a freshly loaded image, you'll have to do this manually with RenderToImage command. * LoadImage (and variants) can now load PBI / BMP / TGA + PNG's files directly from memory. To do so, the address of the data is given as a String in place of the filename with an & symbol prefix. eg LoadImage "&"+Str$(Ptr),Index - They can also be automatically loaded from the resource buffer. See #AddResource and Example #2 bellow Mini Tutorial #1: This example loads an image from disc into image slot (index) #1 in memory, displays it to the screen at 100x, 100y then waits for the user to press a key before ending (Sample ONLY)
Mini Tutorial #2: Load Image From Memory This example shows how we can use the LoadImage command to load from memory and not just disc. To demonstrate this, we first need to store an image in memory to load. The image load from memory routines expect a pointer to a the size of the image (stored as an integer) followed by the the image data. So an images that's 10000 bytes long, requires an integer header making it 10004 bytes in memory. In order to load it, we would give the loader the address of the size integer and as long as the image data is after in, it should load ok. Loading images from memory is normally used for data security purposes, which is where a programmer would store first pre-process their media files and store them in an encrypted/scrambled state. The program/game then loads the encrypted media files into memory, decrypts/descrambles the data in memory and then loads that media from memory directly. This saves ever having to store the decrypted media data in a temporary state on disc.
|
||
Example Source: Download This Example
|
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |