Images - QB64 Wiki

Images

From QB64 Wiki

Jump to: navigation, search

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.


(Return to Table of Contents)

_PUTIMAGE

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 as a function like this;


_PUTIMAGE _DEST, 0


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


SCREEN imagehandle


or;


SCREEN _DEST


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


(Return to Table of Contents)

_ALPHA

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.


Contents

Syntax

result& = _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.



For more information about images, see this documentation: QB64 2D Prototype V1.0


(Return to Table of Contents)

Image file types


(Return to Table of Contents)

QB64 statements and functions


(Return to Table of Contents)



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Personal tools