| | | | each row of the bitmap file's pixel array (see Figure 21-1) corresponds to a portion of one of the display's scan lines. Sometimes a row of the bitmap file itself is referred to as a scan line. (For more on hardware raster scanning, let me suggest my book Understanding Personal Computer Hardware, published by SpringerVerlag, New York.) | | | | | | In this regard, bitmaps can be classified into two categories, distinguished by whether the rows of pixels appearing in the bitmap file are scanned in normal order or in reverse order. In the top-down bitmap file, the first row of pixels in the bitmap file corresponds to the top row of the bitmap image. This means that the origin of the bitmap array, that is, the pixel array entry (0,0) represents the upper-left corner of the bitmap image. In a bottom-up bitmap file, the first row of pixels in the bitmap file corresponds to the last (bottom) row of the bitmap image. Hence, the origin represents the lower-left corner of the bitmap image. | | | | | | Simply put, a top-down bitmap file builds the bitmap image from the top down, whereas a bottom-up bitmap file builds the bitmap image from the bottom up. | | | | | | Device-Independent Bitmaps | | | | | | The main compatibility problem related to bitmaps is the rendering of color. The original device-dependent bitmap (DDB) format, used in Windows 3.0 and earlier, uses a very simple method for representing colors. Each pixel value in the bitmap's data array is an index into a color table that is maintained by Windows itself. In this case, the color table is not part of the bitmap file. Hence, if a bitmap is created on one system and displayed on another system with a different color table, the original colors may be replaced. This is not good. | | | | | | To mitigate this problem, the device-independent bitmap, or DIB, was invented. A DIB file contains all of the color information used by the bitmap, thus making it portable. | | | | | | To understand how this is done, we must first note that colors are generally represented in a bitmap by the RGB color model, in which each color is described by a 3-byte (24-bit) number 8 bits to specify the intensity of red, 8 bits to specify the intensity of green, and 8 bits to specify the intensity of blue. (The colors red, green, and blue are the primary colors for the model.) Thus, for instance, the color &HFFFFFF indicates full intensity for each color, thus producing white; &H0 produces black; and &H00FF00 produces full intensity (bright) green. You can check this yourself by using a VB picturebox control and executing the code: | | | | | | Picture1.BackColor = RGB(0, &HFF, 0) | | | | | | Incidentally, there are other color models. For instance, the CYMK color model uses the primary colors cyan, yellow, magenta, and black. The RGB color model is used by display monitors, and the CYMK model is used by color printers. This is one reason why it is so difficult to get screen and printer colors to match. | | |