Blitz3D+ Command Reference

LoadImage ( bmpfile$ )

Parameters

bmpfile$ - path to the image file to load

Description

Loads an image from disk and returns a handle to it.

The handle is just a number that identifies the loaded picture. Keep it in a variable - a Global one if you load at startup and draw from inside functions - and pass it to DrawImage, MaskImage, FreeImage and the rest. Nearly every media command in the language works this way, so it is worth getting comfortable with early.

The modern runtime decodes images through Windows' own imaging component, so BMP, PNG, JPEG, GIF and TIFF files all load. PNG is the sensible default for game art. The path is relative to your program unless you give a full one.

Black (RGB 0,0,0) is the transparent colour on a freshly loaded image. If your artwork uses magenta or some other key colour instead, call MaskImage straight after loading. If AutoMidHandle is on, the image also arrives with its handle centred.

The command returns 0 when the file is missing or cannot be decoded, so it is worth checking rather than finding out later with a mystery error. Image handles do not survive a mode change - after a call to Graphics you should load your artwork again.

See also: LoadAnimImage, CreateImage, FreeImage, SaveImage, DrawImage, MaskImage.

Example

; LoadImage Example
; -----------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; LoadImage reads an image file and returns a handle for drawing
player=LoadImage("media/player.bmp")

; A small star sprite for the backdrop
star=LoadImage("media/star1.bmp")

; Scatter the stars at fixed random positions
SeedRnd MilliSecs()
Dim star_x(19)
Dim star_y(19)
For i=0 To 19
    star_x(i)=Rand(0,639)
    star_y(i)=Rand(0,479)
Next

While Not KeyDown(1)

    Cls

    ; Draw the starfield backdrop
    For i=0 To 19
        DrawImage star,star_x(i),star_y(i)
    Next

    ; Fly the loaded ship wherever the mouse points
    DrawImage player,MouseX(),MouseY()

    Text 0,0,"Move the mouse to fly the ship   Esc: exit"
    Text 0,20,"LoadImage returned image handle "+player

    Flip

Wend

End

Index