BMP Tutor - Ref-01 API/Data Structure Reference

Category: BMP Tutor Series (API)

Date: 02-16-2022

Return to Index


 
'There are a several API discussed in these BMP Tutor snippets. This page
'provides a diagram of how many of the API tie together, shows the data
'structure for bitmap file, shows the data structures for the two types
'of bitmaps bitmaps (DDB and DIB), lists members of all the data structures
'and shows the arguments for each of list API.
 
'When you've gone through all of the BMP Tutor snippets, this page should
'serve as a reference point to help tie together all of the elements needed
'to work with bitmaps.
 
 
                                                                        CreateCompatibleDC()
                                                                                 |
                                                                                 V
                                                                           *-----------*
*.bmp    -->  LoadImage() --> DDB                --> SelectObject()  -->   |           |
*.bmp    -->  LoadImage() --> DIBSection         --> SelectObject()  -->   |           |
                                                                           |           |
resource -->  LoadImage() --> DDB                --> SelectObject()  -->   |           |
resource -->  LoadImage() --> DIBSection         --> SelectObject()  -->   |  Device   |
                                                                           |  Context  |
scratch  -->  CreateCompatibleBitmap() --> DDB   --> SelectObject()  -->   |           |
                                                                           |           |
scratch  -->  CreateDIBSection() --> DIBSection  --> SelectOjbect()  -->   |           |
                                                                           |           |
                                                                           *-----------*
                                                                                 |
                                                                                 |
-------Data Structures -------------                                             |
DDB          Bitmap                                                              |
                                                                                 |
DIB          BITMAPINFO                                                          |
             --> BITMAPINFOHEADEr                                                |
             --> ColorArray                                                      |
                                                                                 |
File         BITMAPFILEHEADER                                                    V
             BITMAPINFOHEADER                                               GetObject()
             ColorDATAArray                                                      |
                                                                          *------+-------*
DIBSECTION   BITMAPFILEHEADER                                             |              |
             ColorDATAArray                                               V              V
                                                                         DDB         DIBSection
                                                                          |
                                                                          V
                                                                      GetDIBits()
                                                                          |
                                                                          V
                                                                      DIBSection
 
 
 
'Bitmap Data Structures
'This list shows the data structures that make up the various bitmap types. The members
'of each data structure are also shown.
 
File                        DDB                        DIB
----------                  -------------              --------------
BITMAPFILEHEADER            Bitmap                     BITMAPINFO
BitmapInfoHeader                                         --> BitmapInfoHeader
ColorBytes                                               --> RGBQuad
 
 
BITMAPFILEHEADER            Bitmap                     RGBQuad
  bfType AS WORD              bmType As Long             rgbBlue As Byte
  bfSize AS DWord             bmWidth As Long            rgbGreen As Byte
  bfReserved1 AS WORD         bmHeight As Long           rgbRed As Byte
  bfReserved2 AS WORD         bmWidthBytes As Long       rgbReserved As Byte
  bfOffBits AS DWord          bmPlanes As Word
                              bmBits As Byte PTR
 
BITMAPINFOHEADER                                       BITMAPINFOHEADER
  biSize As DWord                                         biSize As DWord
  biWidth As Long                                         biWidth As Long
  biHeight As Long                                        biHeight As Long
  biPlanes As Word                                        biPlanes As Word
  biBitCount As Word                                      biBitCount As Word
  biCompression As DWord                                  biCompression As DWord
  biSizeImage AS DWord                                    biSizeImage AS DWord
  biXPelsPerMeter As Long                                 biXPelsPerMeter As Long
  biYPelsPerMeter As Long                                 biYPelsPerMeter As Long
  biClrUsed AS DWord                                      biClrUsed AS DWord
  biClrImportant AS DWord                                 biClrImportant AS DWord
 
                             CreateBitmap               GetDIBits         (Create DIB From DDB)
                             CreateBitmapIndirect       CreateDIBSection  (Create DIB From scratch)
                             CreateCompatibleBitmap     SetDIBitsToDevice (Use DIB to Set Pixels On Display)
                             CreateDiscardableBitmap    StretchBibits     (Use DIB to Set Pixels On Display
                             CreateDIBitmap (Create DDB From DIB)
 
 
'Note: ColorBytes for a File are organized as BGR, word aligned, and (usually) upside down
'rows (scanlines).  The bytes are simply stored in the file sequentially and may be read
'in however the programmers choses, such as single-dimension or two-dimensional arrays.
'A two-dimensional array is generally considered the most convenient to use on coding.
 
'Note: You can manually create the data structures and image color data arrays to create
'a bitmap file and a DIB.  A DDB cannot be manually created because the image color data
'is stored in the device for which the color format is not available.
 
 
'These API, from the above diagram, are frequently used when working with bitmap.
'Here are their arguments.
 
GetDIBits                      'hDC, hBMP, uStartScan, cScanLines, lpvBits, lpbi, uUsage
CreateDIBSection               'hDC, pbmi, iUsage, ppvBits, hSection, dwOffset
SetDIBitsToDevice              'hDC, xDest, yDest, dwWidth, dwHeight, xSrc, ySrc, uStartScan, cScanLines, lpvBits, lpbmi, fuColorUse
StretchDIBits                  'hDc, xDest, yDest, nDestWidth, nDestHeight, xSrc, ySrc, nSrcWidth, nSrcHeight, lpvBits, lpBitsInfo, iUsage, dwRop
 
CreateBitmap                   'nWidth, nHeight, cPlanes, cBitsPerPel, lpvBits
CreateBitmapIndirect           'lpbm
CreateCompatibleBitmap         'hDC, nWidth, nHeight
CreateDiscardableBitmap        'hDC, nWidth, nHeight
CreateDIBitmap                 'hDC, lpbmih, fdwInit, lpbInit, lpbmi, fuUsage
 
 
'These bitmap API, not in the diagram, are used less frequently. Here are their arguments.
SetDIBits                      'hDC, hBMP, uStartScan, cScanLines, lpvBits, lpbi, fuColorUse
GetBitmapBits                  'hBMP, cBuffer, lpvBits
SetBitmapBits                  'hBMP, cBytes, lpBits
 
 
'These API are listed at MSDN under other topics, but are useful in working with bitmaps.
LoadImage                      'hInst, lpszName, uType, cxDesired, cyDesired, fuLoad
GetObject                      'hgdiObj, cbBuffer, lpvObject
SelectObject                   'hDC, hgdiObj
GetDC                          'hWnd
GetDCEx                        'hWnd, hrgnClip, flags
GetCompatibleDC                'hDC
CreateDC                       'lpszDriver, lpszDevice, lpszOutput, lpInitData
DeleteObject                   'hObject
DeleteDC                       'hDC
ReleaseDC                      'hWnd, hDC
 
'gbs_00444
'Date: 03-10-2012


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