QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

Images are areas of graphics stored in memory, the most common image is the program screen itself, where graphics are displayed. This image is designated as image handle 0 or _DEST 0. QB64 refers to the image memory by using negative LONG handle values. Those values can then be referred to using other functions such as _WIDTH and _HEIGHT to find the image properties. Statements like SCREEN or _PUTIMAGE can use the image handle to display the image when necessary. QBasic functions like POINT can read the colors, even 32 bit _ALPHA colors.

Images are called by other names in other programming languages or in different situations, examples of other names can be “surfaces”, “pages” or “layers”.

QB64 Images

You can create a program screen image by using the _NEWIMAGE function. _NEWIMAGE returns a handle for you to use as a reference to that image. The handle is a negative number below -1 where -1 indicates a failure to load an image.

For the image handle parameter in a statement you can also use any positive number and this handle will not need to be defined by _NEWIMAGE or anything else. In this case the image referred to is the screen page of that value. This is why image handle 0 refers to the screen, specifically screen page 0.

You can also load an image from a file using the _LOADIMAGE function (click the link for further information), or retrieve the handle to a copy of a image by using the _COPYIMAGE function.

All images except for the screen are hidden from view unless drawn onto the screen, this enables you to draw multiple things on an image and then display all of it at once, enabling smooth animation (amongst many other things), you can also put multiple images ontop of one image and then display that image to the screen to enable all sorts of effects, like parallax scrolling and objects moving in front of as well as behind each other.


To set which image you want to draw graphics on, use _DEST, all drawing will now go to the desired image instead of the screen (to enable drawing to the screen set _DEST 0), if you want to retrieve information about a image you use _SOURCE instead, as when you want to know the color a pixel has at a certain coordinate you would use _SOURCE along with POINT (see the _SOURCE example for more information about this). If you have drawn graphics on one image you can display it to the screen using _PUTIMAGE, like this;

_PUTIMAGE imagehandle, 0

Where imagehandle is the handle you have drawn, or if you don’t know the image handle you can use _DEST (function) as a function like this;


You could also use the SCREEN (statement) statement to display the image to the screen like this;

SCREEN imagehandle



Just be careful so that _DEST is indeed a negative number other than -1.


If you want a color to be transparent you would use the _CLEARCOLOR statement, the _CLEARCOLOR statement also has a optional argument as to which image you want the color to be transparent on, if this argument is set then the color will only be transparent on that particular image. If you want the color to be solid again you would use _NONE as the color argument (see _CLEARCOLOR statement for further details).

The _SETALPHA statement also enables transparency (_CLEARCOLOR just sets the transparency level to full (which is 0) on images that have an alpha channel), to enable partial transparency you need a 32-bit image which has an alpha channel (a PNG image may already contain alpha information), the alpha level is between 0 (transparent) and 255 (opaque). If you have a 32-bit image but don’t want to alpha blend it you have to turn it off using _DONTBLEND. To turn it on again you can use the _BLEND statement (which is on by default).

To put an image on top of another image you would use _PUTIMAGE, if you want to put/stretch the whole image on top of another you would just omit the range arguments and if you only want to put part of the image on top of another image you would use the range arguments as necessary. Keep in mind that _PUTIMAGE will stretch the image to fit the destination range. If the coordinates are inverted then the image will be inverted accordingly (enables flipping).

The _ALPHA function returns the alpha channel level of a color value.


*result&* = [_ALPHA](_ALPHA)(c&[, imageHandle&])

_RED32, _GREEN32, _BLUE32 and _ALPHA32 are all equivalent to _RED, _GREEN, _BLUE and _ALPHA but they are highly optimized and only accept a 32-bit color (B8:G8:R8:A8). Using these in your code (as appose to dividing then ANDing 32-bit color values manually) makes your code easy to read too.

Image file types

QB64 statements and functions