Bitmap Sections

Bitmap sections let you work with subregions of 256-color and direct color bitmaps. Functions are provided for extracting a bitmap section from another bitmap, and also for inserting a bitmap section into another bitmap. Bitmap sections are themselves bitmaps, so anything you can do with a 256-color or direct color bitmap can also be done with a bitmap section.

The fg_cut() function extracts a 256-color bitmap section from a 256-color bitmap. Its first parameter is the name of the array containing the source bitmap, and its second parameter is the name of the array to receive the bitmap section. The third and fourth parameters specify the x and y coordinates within the source bitmap that define the left and bottom edges of the bitmap section (the bottom row of a bitmap is considered row zero; the leftmost column is considered column zero). The next parameter is the width of the source bitmap in pixels, and the last two fg_cut() parameters define the bitmap section width and height in pixels. The fg_cutdcb() function has the same parameters as fg_cut() but works with direct color bitmaps instead of 256-color bitmaps. Neither fg_cut() nor fg_cutdcb() modify the source bitmap in any way.

The fg_paste() function inserts a 256-color bitmap section into a 256-color bitmap. Its parameters are essentially the same as fg_cut(), but the parameters pertaining to the source bitmap instead refer to the larger bitmap into which fg_paste() will insert the bitmap section. For example, the x and y coordinates specified as the third and fourth parameters define the position where fg_paste() will insert the bitmap section, not where it will extract it from. The fg_pastedcb() function provides the same functionality for direct color bitmaps.

Suppose we have a 64x64 256-color bitmap and we want to copy the 8x8 block of pixels in its upper left corner to its lower right corner. Since the bottom row of a bitmap is row zero, we'll use fg_cut() to extract an 8x8 bitmap section whose lower left corner is at x=0 and y=56 within the 64x64 bitmap. Then we'll insert the bitmap section back into the 64x64 bitmap at x=56 and y=0 with fg_paste(). Here's how to do it:


BYTE Bitmap[64*64];
BYTE Section[8*8];


Bitmap : array [1..64*64] of byte;
Section : array [1..8*8] of byte;

Visual Basic:

Option Base 1
Dim Bitmap(64 * 64) As Byte
Dim Section(8 * 8) As Byte
Call fg_cut(Bitmap(1), Section(1), 0, 56, 64, 8, 8)
Call fg_paste(Bitmap(1), Section(1), 56, 0, 64, 8, 8)

For direct color bitmaps, we would use fg_cutdcb() and fg_pastedcb() rather than fg_cut() and fg_paste(). We would also need to increase the size of the Bitmap and Section arrays to hold two bytes per pixel for high color, or three bytes per pixel for true color.

<< Prev

Next >>

Fastgraph Home Page


copyright 2001 Ted Gruber Software, Inc.