SaveBuffer ( buffer,bmpfile$ )

Parameters

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

bmpfile$ - path of the file to write; a name ending in .png writes a PNG, any other name a BMP

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 BackBuffer(),"shot.bmp", called once the frame is drawn and before Flip, 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. BackBuffer() is the frame you have just drawn but not yet shown with Flip. In a 3D program it holds the last RenderWorld with the 2D you drew since on top, so a shot of it contains the whole scene. FrontBuffer() only shows the last frame in a 2D program, where Flip copies the finished frame into it; in a Graphics3D program the 3D never reaches the front buffer, so saving it gives you none of the scene. An ImageBuffer saves an image without needing SaveImage.

Name the file .png for a compressed 24-bit PNG - the better choice for screenshots you will share - or anything else for an uncompressed 24-bit Windows BMP, as in classic Blitz3D, where 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