GDI Article - DIBs and Their Use

Category: Graphics - GDI

Date: 02-16-2022

Return to Index


 
DIB purpose is to allow movement of bitmaps from one device to another deivce
 
GetDIBits Translates a device-dependent bitmap into the DIB format
SetDIBits Translates a 's information into device-dependent form
CreateDIBitmap Creates a device-dependent bitmap initialized with DIB information
SetDIBitsToDevice Sets a DIB directly to the output surface
StretchDIBits Moves a rectangle from the DIB to a rectangle on the destination surface, stretching or compressing as necessary
CreateDIBPatternBrush Creates a pattern brush using a DIB for the bitmap description
 
DDB appears in the system as a bitmap object
 
The file extension of a Windows DIB file is BMP
- BitmapFileHeader
- BitmapInfoHeader
- RGBQuad Array)
 
Every scanword is DWord-aligned.
Scanlines are stored upside down.
 
Using SetDIBits is reasonably straightforward. A DIB is taken
from somewhere (for example, from the Clipboard or from a disk
fileand is converted to a bitmap object, which can then be
selected into a DC and blted to the screen for display. This
is the simplest way to display a DIB.
 
 
The following is a simple display of a DIB to a DC (with no error handling):
 
HBITMAP hBitmap;
HDC hMemDC;
 
hBitmap = CreateCompatibleBitmap(hDC, (WORD)lpInfo->biWidth,
          lpInfo->(WORD)biHeight);
hMemDC = CreateCompatibleDC(hDC);
SetDIBits(hDC, hBitmap, 0, (WORD)lpInfo->biHeight, lpBits,
         lpInfo, DIB_RGB_COLORS);
hBitmap = SelectObject(hMemDC, hBitmap);
BitBlt(hDC, 0, 0, (WORD)lpInfo->biWidth, (WORD)lpInfo->biHeight,
      hMemDC, 0, 0, SRCCOPY);
DeleteObject(SelectObject(hMemDC, hBitmap));
DeleteDC(hMemDC);
 
 
CreateDIBitmap
 
The following code demonstrates calling CreateDIBitmap with the usual case:
 
hBitmap = CreateDIBitmap(hDC, lpInfo, CBM_INIT, lpBits, lpInfo,
          wUsage);
 
 
This is equivalent to:
 
hBitmap = CreateCompatibleBitmap(hDC, (WORD)lpInfo->biWidth,
          (WORD)lpInfo->biHeight);
SetDIBits(hDC, hBitmap, 0, (WORD)lpInfo->biHeight, lpBits, lpInfo,
          wUsage);
 
 
's implementation skips the SetDIBits part if the third parameter
is not set with the CBM_INIT flag. This function makes for nice shortcut
coding of the conversion from DIB to device-dependent bitmap.
 
 
Because all DIB functions expect the DIB as two pointers, one to the
header and one to the bits ...
 
'gbs_01006
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm