Date: 02-16-2022
Return to Index
created by gbSnippets
'API Summary ===================================================================
GetDeviceCaps - get resolution, color format (planes/bpp), pallette size, if supports DIB-to-DDB, ...
GetDIBits - create DIB from DDB
TransparentBlt - copy all pixels to dest except pixels of specified color
SetDIBits - use DIB to set pixels on display device
SetDIBitsToDevice - use DIB to set pixels on display device
StretchDIBits - use DIB to set pixels on display device
BitBlt - faster was to set pixels on display device
'=========================================================
'=========================================================
'=========================================================
Bitmap is GDI object, can be selected into a DC
Graphic Objects: bitmaps, brushes, fonts, pens
Bitmap classifications: DIB and DDB
Bitmap is a collection of structures:
- Header
- Palette
- Array of bits
Scan line: row of adjacent pixels on a video display
Bottom-up DIB - bits begin with bottom line
Top-Down DIB - bits begin with top line
DDB - bits begin with top line
Classifications
Header Types
JPG/PNG Extensions
DC and Drawing Surfaces
Create
Rotate
Scale
Use as Brush
Storage
Compression
Alpha Blending
Smooth Shading
ICM-Enabled Functions
'Classifications ===========================================================
DIB - modern bitmap type
DDB (also called GDI Bitmap) - early versions (still useful for better GDI performance)
DIB '----------------------------------------
- BitmapInfoHeader
- Pallette (optional) (RGBQuad structure)
- Bit Array (RGBQuad)
- Profile data (optional)
Bottom-up: height is +
Top-Down : height is -
Color planes = 1
Color bits = 24,32
DDB to DIB Conversion: GetDIBits
API - GetDeviceCaps
- TransparentBlt (copy with selected transparency)
- SetDIBitsToDevice/StretchDIBits - set pixels on display device
- BitBlt is faster than SetDIBisToDevice
DDB '----------------------------------------
- Single structure - Bitmap structure
- called a compatible
- Does not contain color values
- Generally faster than DIB
Create DDB : CreateBitmap
CreateCompatibleBitmap
CreateBitmapIndirect
Create DDB from DIB - CreateDIBitmap (same as CreateCompatibleBitmap + SetDIBits)
'Headers ===========================================================
BitmapInfoHeader
BitmapV5header - extended version of BitmapInfoHeader
DIB Format
- BitmapFileHeader - BitmapInfoHeaders/BitmapV5Header
- Color table (optional) - not used with 24/32 bpp bitmaps
- Bitmap Data (RGBQuad Array)
- Profile data (optional)
By default, bitmap data is bottom-up
Scan lines are DWord aligned (example: 10x10 pixel, 24bpp will have 2 padding bytes each scan line)
Type BITMAPINFOHEADER
biSize As Dword
biWidth As Long
biHeight As Long
biPlanes As Word
biBitCount As Word
biCompression As Dword
biSizeImage As Dword
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Dword
biClrImportant As Dword
End Type
'DC and Drawing Surfaces ===========================================================
CreateDC ....>
GetDC ....> size of client area
GetWindowDC ...> size of entire Window
GetDCEx ....>
GetDC() <---> ReleaseDC
'Create ===============================================================
These let you specify w/h of bitmap
CreateBitmap + planes/bpp
CreateBitmapIndirect + planes/bpp
CreateCompatibleBitmap uses specified device to obtain planes/bpp
CreasteDiscardableBitmap uses specified device to obtain planes/bpp
CreateDIBitmap create DDB from DIB
use DeleteObject to delete any of the above
'Copy/Rotate/Scale ===============================================================
BitBlt - copies to a rectangle
PlgBlt - copies to a parallelogram
StretchBlt - scales to a rectangle
StrtechBltMode determines how colors are handled in Str
'Bitmap as Brush
PatBlt - replicates brush in a rectangular area (rectangular only)
FloodFill - replicates brush in area bounded by a color (can be non-rect)
PatBlt combines color data. FloodFill simply colors all pixels.
'File Storage ==================================================================
BitmapFileHeader
BitmapInfoHeader
RGBQuad - array of bits
Color index array
Type BitmapFileHeader Type BitmapInfoHeader
bfType As Word biSize As Dword
bfSize As Dword biWidth As Long
bfReserved1 As Word biHeight As Long
bfReserved2 As Word biPlanes As Word
bfOffBits As Word biBitCount As Word
End Type biCompression As Word
biSizeImage As Dword
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Dword
biClrImportant As Dword
End Type
'Compression ==================================================================
Does not apply to 24/32 bpp bitmaps.
Windows supports formats for compressing bitmaps that define their colors
with 8 or 4 bits-per-pixel.
'gbs_00918
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm