Skip to main content

SetGraph

SetGraph (Statement)

Format

setgraph internal_image_identifier
setgraph ( internal_image_identifier )
setgraph
setgraph ( )

Description

Redirects all graphics output to an image held in memory, or sends it back to the graphics output window.

Given an identifier returned by ImageNew, ImageLoad, or ImageCopy, every drawing statement that follows — Plot, Line, Rect, Circle, Ellipse, Arc, Chord, Pie, Poly, Text, Stamp, ImageDraw, and so on — paints onto that image instead of onto the screen.

Used with no argument, or with an empty string, drawing returns to the graphics output window.

While drawing is redirected to an image:

Unloading the image that is currently being drawn on returns drawing to the graphics output window automatically.

Errors

If the value is an image identifier but no such image is loaded, ERROR_IMAGERESOURCE is raised and drawing returns to the graphics output window. If the value is not an image identifier at all, ERROR_INVALIDRESOURCE is raised and the current drawing target is left unchanged. See Error Codes.

Example

graphsize 300,300
clg

color blue
circle 50,50,50

# copy the top left corner of the window into memory
i = imagecopy(0,0,100,100)

# draw on the copy, not on the screen
setgraph i
color red
rect 0,0,20,20

# send drawing back to the screen
setgraph
color green
rect 0,150,150,150

# place the modified copy over the green square
imagedraw i, 0, 150
refresh
unload i

See Also

Clg, GraphHeight, GraphWidth, ImageCopy, ImageDraw, ImageLoad, ImageNew, ImgSave, Pixel, Unload

Availability

Present in BASIC-256 2.0 alongside the Image* statements, but not previously documented. Described here from the BASIC-256 v2.1 continuation project source.