Blitz3D+ Command Reference

CreateImage ( width,height[,frames] )

Parameters

width - width of the image in pixels (of each frame, if there is more than one)

height - height of the image in pixels

frames (optional) - number of frames to create; 1 (default)

Description

Creates a new blank image in memory and returns its handle.

Use this when the picture you want does not exist on disk: a render target for an effect, a scratch surface to compose a HUD on, a procedurally generated starfield or noise texture, or an empty holder to grab part of the screen into with GrabImage.

To draw into it, point the drawing commands at one of its frames with SetBuffer ImageBuffer(pic) - then Cls, Rect, Text and friends all land inside the image instead of on the screen. Remember to point the buffer back at BackBuffer() when you are finished.

Asking for several frames gives you an animation strip built at runtime, indexed from 0 like one loaded by LoadAnimImage; every frame is the same width and height. If AutoMidHandle is on when you call this, the new frames get a centred handle.

The image comes back filled with black, which is also the default mask colour, so a freshly created image drawn with DrawImage is completely transparent until you draw something into it. The command returns 0 if the image could not be created, and the image stays in memory until you call FreeImage.

See also: LoadImage, CopyImage, FreeImage, ImageBuffer, GrabImage, SetBuffer.

Example

; CreateImage Example
; -------------------

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

; Create a blank 64x64 image - no file needed
target=CreateImage(64,64)

; Paint a target sprite into the new image with drawing commands
SetBuffer ImageBuffer(target)
Color 255,0,0
Oval 2,2,60,60,True
Color 255,255,255
Oval 12,12,40,40,True
Color 255,0,0
Oval 22,22,20,20,True
SetBuffer BackBuffer()

; Start it bouncing around the screen
x#=100
y#=100
dx#=3
dy#=2

While Not KeyDown(1)

    Cls

    x=x+dx
    y=y+dy
    If x<0 Or x>576 Then dx=-dx
    If y<0 Or y>416 Then dy=-dy

    DrawImage target,x,y

    Text 0,0,"Esc: exit"
    Text 0,20,"target=CreateImage(64,64) - painted with Oval, then drawn like any image"

    Flip

Wend

End

Index