Displaying Monochrome BitmapsThe fg_drawmap() function displays monochrome bitmaps in 256-color or direct color virtual buffers. Its first parameter is the name of the bitmap array, the second is the width of the bitmap in bytes, and the last is the height of the bitmap in pixels. The fg_drawmap() function displays the image in the current color, with its lower left corner at the graphics cursor position in the active virtual buffer. Suppose we want to display the triangle monochrome bitmap in the middle of a 320x200 virtual buffer, just as we did using a 256-color bitmap. To do this, its lower left corner must be at the screen space position (156,101). The following code will accomplish this:
C/C++:
Delphi:
Visual Basic:
Note that we need two calls to fg_drawmap(), one for each color in the image, and how we use fg_setcolor() before each call to fg_drawmap() to define the current color. The result is a triangle with a blue perimeter and green interior. Like fg_drwimage(), fg_drawmap() does not perform clipping when displaying an image. If you want to display a monochrome bitmapped image constrained by the current clipping limits, use fg_clipmap() instead of fg_drawmap(). The fg_clipmap() function takes the same three parameters as fg_drawmap(). The different color bitmaps used by fg_drawmap() do not all have to be the same size. In our triangle example, the perimeter is 9 pixels wide by 5 pixels high, but the interior is only 5 pixels wide by 3 pixels high. Hence, the bitmap for the interior pixels only requires one byte for each of its three rows, so we can store it in a three-byte array that would look like this:
We could then use this code to display the triangle bitmaps:
C/C++:
Delphi:
Visual Basic:
In this example, the time required to execute the second call to fg_move() may not be worth the saving of 7 bytes of bitmap array. When array space is critical, or when the images are larger, the use of smaller bitmaps for certain colors may be more valuable. Yet another possibility for this example would be to shift the elements of the interior bitmap two pixels to the left. In this way, the bitmap would be aligned against the left side of the array, as the perimeter bitmap is. The three values comprising the interior bitmap would then become F8, 70, and 20. We also would need to change the x coordinate in the second call to fg_move() from 156 to 158.
|
 
copyright 2001 Ted Gruber Software, Inc.