SaveBuffer ( buffer,bmpfile$ )

Parameters

buffer - buffer to save, such as FrontBuffer(), BackBuffer() or ImageBuffer(pic)

bmpfile$ - path of the file to write

Description

Writes the contents of a buffer to a file. Returns True on success, False if the file could not be written.

This is the screenshot command. Bind a key to SaveBuffer FrontBuffer(),"shot.bmp" and your players can grab what is on screen. It is just as handy during development for capturing a frame you want to study, or for dumping an off-screen surface to see what is actually in it.

Pick the buffer to match the moment. FrontBuffer() is what the player can see right now. BackBuffer() is the frame you have just drawn but not yet shown with Flip - grab that one if you want the shot to contain everything you drew this loop. An ImageBuffer saves an image without needing SaveImage.

The file is always an uncompressed 24-bit Windows BMP regardless of the extension you give it, so a full-screen shot is several megabytes. Give consecutive shots different names - the file is overwritten without warning - and expect the write to take long enough to be visible as a hitch, which is fine for a screenshot key and not fine every frame.

See also: LoadBuffer, SaveImage, FrontBuffer, BackBuffer, GrabImage.

Example

; SaveBuffer Example
; ------------------

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

player=LoadImage("media/player.bmp")
angle#=0
saved=-1

While Not KeyDown(1)

    Cls

    ; A little squadron worth photographing
    angle=angle+2
    For i=0 To 4
        DrawImage player,120+i*100,240+50*Sin(angle+i*45)
    Next

    ; S saves everything drawn to the back buffer so far as a screenshot
    If KeyHit(31) Then saved=SaveBuffer(BackBuffer(),"demo_screenshot.bmp")

    Text 0,0,"S: screenshot the back buffer   Esc: exit"
    If saved=1 Then
        Text 0,20,"SaveBuffer wrote demo_screenshot.bmp - try the LoadBuffer example!"
    ElseIf saved=0 Then
        Text 0,20,"SaveBuffer returned 0 - could not write the file"
    End If

    Flip

Wend

End

Index