OWBasic for Pocketviewer

Home INTRO Group GRAPHIC Alphabetical Index

Storing Bitmaps in Integer Arrays

With DRAWICON, SETICONPIX and ICONPIX one can manipulate graphic bitmaps. Even if the name ICON suggests only small objects, also bitmaps of the size of the screen can be used.

Bitmaps are stored in integer arrays. The first two elements contain the size of the bitmap in pixels. The following elements contain the image data. Image data is organized bytewise. Use BYTES to split an integer into the bytes. Every byte contains 8 pixels. Each new line starts with a new byte (byte aligned). The array size required to store a bitmap can be calculated in the following way:

Calculate the number of bytes for one line: If x size is 50 pixels, then 6 bytes and 2 bits are needed. Because of the byte alignment the remaining 6 bits of the seventh byte can't be used and we need seven bytes for each line.
Calculate the total number of bytes from the size in y direction: Assume the size in y direction is also 45, then we need 45 times 7 bytes or 315 byte.
If the number of bytes is odd, we have to add an additional byte, because an integer variable represents two bytes. 316 bytes are 158 integers.
Two integers are required to store the sizes, so we need an array with 160 elements.

Example of bitmap creation:

DIM bitmap[159]: ! define array with 160 elements
clear bitmap
bitmap[0]=50:    ! size x
bitmap[1]=45;    ! size y
Now we can create the bitmap setting pixels with SETICONPIX.

Home INTRO Group GRAPHIC Alphabetical Index