CopyImage ( image )

Parameters

image - handle of the image to duplicate

Description

Duplicates an image in memory and returns a handle to the new copy.

Load your artwork once, then make as many copies as you need. The copy is a genuinely separate image: drawing into it with ImageBuffer, recolouring it, or scaling it with ScaleImage leaves the original untouched. That is the usual reason to reach for this command - you keep one pristine master and hand out mutated versions, for example a set of tinted or pre-rotated copies of the same sprite built once at startup.

Every frame of an animated image is copied, and the copy inherits the original's handle position and mask colour, so it draws exactly like the source until you change it.

The copy is a second image in memory, not a cheap reference. Copying a big image many times costs real memory, and each copy needs its own FreeImage when you are done with it.

See also: LoadImage, CreateImage, FreeImage, DrawImage, MaskImage.

Example

; CopyImage Example
; -----------------

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

; Load a ship, then make an independent copy of it
original=LoadImage("media/player.bmp")
copy=CopyImage(original)

; Paint red stripes on the COPY only - the original is untouched
SetBuffer ImageBuffer(copy)
Color 255,0,0
Rect 0,14,32,4,True
Rect 0,24,32,4,True
SetBuffer BackBuffer()

angle#=0

While Not KeyDown(1)

    Cls

    ; Both ships bob together so they are easy to compare
    angle=angle+2
    y=220+30*Sin(angle)
    DrawImage original,220,y
    DrawImage copy,400,y

    Text 236,320,"original",True
    Text 416,320,"copy",True

    Text 0,0,"Esc: exit"
    Text 0,20,"copy=CopyImage(original) - editing the copy leaves the original alone"

    Flip

Wend

End

Index