Images: Difference between revisions
TheSnowDog (talk | contribs) m (QBasic capitalisation) Tag: visualeditor |
m (Removed protection from "Images") |
(No difference)
|
Revision as of 15:33, 1 June 2022
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.
_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.
_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 Template:KW function returns the alpha channel level of a color value.
Syntax
result& = Template:KW(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
- Bitmaps
- Creating Icon Bitmaps
- Icons and Cursors
- GIF Images
- Creating Icons from Bitmaps
- SaveIcon32 (convert any image to icon)
- SAVEIMAGE (convert any image to bitmap)
- Text Using Graphics
- $EXEICON
QB64 statements and functions
- _ALPHA (function)
- _ALPHA32 (function)
- _BACKGROUNDCOLOR (function)
- _BLEND (sub)
- _BLEND (function)
- _BLUE (function)
- _BLUE32 (function)
- _CLEARCOLOR (sub)
- _CLEARCOLOR (function)
- _COPYIMAGE (function)
- _COPYPALETTE (sub)
- _DEFAULTCOLOR (function)
- _DEST (sub)
- _DEST (function)
- _DISPLAY (function)
- _DONTBLEND (sub)
- _FONT (sub)
- _FONT (function)
- _FONTHEIGHT (function)
- _FONTWIDTH (function)
- _FREEFONT (sub)
- _FREEIMAGE (sub)
- _GREEN (function)
- _GREEN32 (function)
- _HEIGHT (function)
- _ICON
- _LOADFONT (function)
- _LOADIMAGE (function) (cannot use Icons)
- _NEWIMAGE (function)
- _PALETTECOLOR (sub)
- _PALETTECOLOR (function)
- _PIXELSIZE (function)
- _PRINTIMAGE (sub) (printer)
- _PRINTMODE (sub)
- _PRINTMODE (function)
- _PRINTSTRING (sub)
- _PRINTWIDTH (sub)
- _PUTIMAGE (sub)
- _RED (function)
- _RED32 (function)
- _RGB (function)
- _RGB32 (function)
- _RGBA (function)
- _RGBA32 (function)
- SCREEN (sub)
- _SCREENIMAGE (function) (desktop)
- _SETALPHA (sub)
- _SOURCE (sub)
- _SOURCE (function)
- _WIDTH (function)