Device-Independent Bitmaps
A DIB contains the following color and dimension information:
- The color format of the device on which the rectangular image was created.
- The resolution of the device on which the rectangular image was created.
- The palette for the device on which the image was created.
- An array of bits that maps red, green, blue (RGB) triplets to pixels in the rectangular image.
- A data-compression identifier that indicates the data compression scheme (if
any) used to reduce the size of the array of bits.
This information is stored in a
BITMAPINFO structure consisting of a
BITMAPINFOHEADER structure followed by two or more
RGBQUAD structures. The
BITMAPINFOHEADER specifies the dimensions of the pixel rectangle, describes the device's color
technology, and identifies the compression schemes used to reduce the bitmap's
size. The
RGBQUAD structures identify the colors that appear in the pixel rectangle.
There are two varieties of DIB: "bottom-up" DIBs, in which the origin lies at
the lower left corner, and "top-down" DIBs, in which the origin lies at the
upper left corner. If the height of a DIB, as indicated by the
biHeight member of the
BITMAPINFOHEADER structure, is a positive value, it is a bottom-up DIB; if the height is a
negative value, it is a top-down DIB. Top-down DIBs cannot be compressed.
The color format is specified in terms of a count of color planes and color
bits. The count of color planes is always 1; the count of color bits is 1 for
monochrome bitmaps, 4 for VGA bitmaps, and 8, 16, 24, or 32 for bitmaps on other
color devices. An application retrieves the number of color bits a particular
display (or printer) uses by calling the
GetDeviceCaps function, specifying BITSPIXEL as the second argument.
The resolution of a display device is specified in pixels per meter. An
application can retrieve the horizontal resolution for a video display, or printer,
by following a three-step process:
- Call the GetDeviceCaps function, specifying HORZRES as the second argument.
- Call GetDeviceCaps a second time, specifying HORZSIZE as the second argument.
- Divide the first return value by the second return value.
The application can retrieve the vertical resolution by using the same
three-step process with different parameters: VERTRES in place of HORZRES, and
VERTSIZE in place of HORZSIZE.
The palette is represented by an array of
RGBQUAD structures that specify the red, green, and blue intensity components for
each color in a display device's color palette. Each color index in the palette
array maps to a specific pixel in the rectangular region associated with the
bitmap. The size of this array, in bits, is equivalent to the width of the
rectangle, in pixels, multiplied by the height of the rectangle, in pixels, multiplied
by the count of color bits for the device. An application can retrieve the size
of the device's palette by calling the
GetDeviceCaps function, specifying the NUMCOLORS constant as the second argument.
The Win32 API supports the compression of the palette array for
8-bit-per-pixel and 4-bit-per-pixel bottom-up DIBs. These arrays can be compressed by using
the run-length encoding (RLE) scheme. The RLE scheme uses 2-byte values, the
first byte specifying the number of consecutive pixels that use a color index and
the second byte specifying the index. For more information about bitmap
compression, see the description of the
BITMAPINFOHEADER structure.
An application can create a DIB from a DDB by initializing the required
structures and calling the
GetDIBits function. To determine whether a device supports this function, call the
GetDeviceCaps function, specifying RC_DI_BITMAP as the RASTERCAPS flag.
An application can use a DIB to set pixels on the display device by calling
the
SetDIBitsToDevice or the
StretchDIBits function. To determine whether a device supports the
SetDIBitsToDevice function, call the
GetDeviceCaps function, specifying RC_DIBTODEV as the RASTERCAPS flag. Specify
RC_STRETCHDIB as the RASTERCAPS flag to determine if the device supports
StretchDIBits.
An application that simply needs to display a preexisting DIB can use the
SetDIBitsToDevice function. For example, a spreadsheet application can open existing charts and
display them in a window by using the
SetDIBitsToDevice function. To repeatedly redraw a bitmap in a window, however, the application
should use the
BitBlt function. For example, a multimedia application that combines animated
graphics with sound would benefit from calling the
BitBlt function because it executes faster than
SetDIBitsToDevice.
- Software for developers
-
Delphi Components
.Net Components
Software for Android Developers
- More information resources
-
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
- Databases for Amazon shops developers
-
Amazon Categories Database
Browse Nodes Database