Return to Index
created by gbSnippets
A Bitmap that can be slected into a DC is called a "Device Dependent Bitmap" and
is represented to the programmer by an HBITMAP handle.
There is another kind of Bitmap called a "Device Independent Bitmap". This type of
bitmap is defined in the windows header files as a number of structs that are filled
in by the programmer. Being "device independent" means there is no HBITMAP that can
be selected into a "Device context" so GDI operations cannot be performed on this type
of bitmap. There are a couple of "DIB" specific functions that can create a DDB (device
dependent bitmap) given a DIB, or copy areas from a DIB onto a DC.
1. Paired bitmaps (color/monochrome) 'white is transparent
- Blit monochrome to destination with AND
- Blit color image using OR
2. Specify a transparent color
From resource in EXE
From file *.bmp
Loading resources directly
Bitmap resources, and bitmap files on disk, are stored in the windows DIB format.
As a resource, a bitmap consists of a BITMAPINFO structure describing the bitmap
followed by the actual image data as an array of bytes.
On disk in a .bmp file, the file starts with a BITMAPFILEHEADER structure, followed
by a BITMAPINFO structure. The start of the image data is indicated by a field in
the BITMAPFILEHEADER structure (not necessarily immediately behind the BITMAPINFO structure.
The solution is to use the resource functions to load the bitmaps directly using
the resource functions to search the exe file for the bitmap resource, and get
pointers to the resource data. As we know the data is stored in DIB format, we
can use the CreateDIBitmap API to create a DDB from the DIB data.
A bitmap to windows is just an array of bytes. In 16 bit and higher modes the color
information of the bitmap data is encoded directly in the data. In 256 color mode
however there is no color information stored in the bitmap. Each byte in the bitmap
is simply an index into a palette of colors.
number of functions that allows the programmer to transfer date from DIBs to DDBs and
the reverse direction. These transfer operations are slow
GDI provides the following functions to transfer bits from
DIBs to DDBs, DDBs to DIBs and DIBs to DCs:
CreateDIBitmap() - this function creates a compatible device dependent bitmap, and initializes it with the passed in DIB.
GetDIBits() - this functions translates a DDBs data into a DIB that is passed in.
SetDIBits() - Like CreateDIBitmap, this function intializes a DDB using the DIB data that is passed in.
SetDIBitsToDevice() - This function copies a DIB directly (translating each pixel of course) onto a display device context.
StretchDIBits() - This function is similar to StretchBlt(), it stretches the source onto a DCs surface - the source data is a DIB.
created by gbSnippets