UNLOADBMP

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

Removes the bitmap image "name" from use by the JB program and frees memory the bitmap was using.

Syntax

  1. unloadbmp "name"

Hints

Unload at Close. Bitmap images loaded with LOADBMP or with GETBMP should be unloaded before your program ends.
Manage Memory. If a program uses many bitmaps, much memory can be consumed. Remember, once a bitmap is loaded, it remains in memory until it is unloaded, or until the program is terminated. To better manage memory usage, unload any bitmap that is no longer needed in a program, and consider unloading and reloading bitmaps if you find keeping too many in memory at one time slows down your system.
Reusing Bmps. If a program will be reusing a bitmap in more than one window, such as an icon or a logo or a background image, you will need to keep it in memory, or else reload the bmp each time a new window is opened. The example shows the effects of unloading a bmp, causing it not to be available for use in a second window.
These commands are generally used when working with bitmaps:

Example

Note that this example shows the effects of using unloadbmp when the intention is to reuse the bmp in a second window.

    'Run this example from the main JustBASIC program folder so
    'the bmp\subfolder and bmp image are accessible.
    loadbmp "copyimage", "bmp\copy.bmp"
    button #main.bt1 "Second Window", [continue], UL, 70, 100, 150, 25

    open "unloadbmp Test" for graphics as #main
    #main "trapclose [quit]"

    print #main, "drawbmp copyimage 10 10; flush"


'    unloadbmp "copyimage"

    'Run program a second time, and remove comment from the unloadbmp
    'statement above. This will cause the bmp to be unloaded from memory.
    'When the second window tries to open, the bitmap named "copyimage"
    'cannot be found, and the program will end with an error.
    wait

[continue]
    open "Second Window" for graphics as #2
    #2 "drawbmp copyimage 10 10; flush"
    #2 "trapclose [quit]"
    wait

[quit]
    unloadbmp "copyimage"
    close #2
    close #main
    end

Useful Procedures

' Place a useful function or sub using this keyword here