Bitmaps and Bitblts
Bitmaps and Bitblts
Bitmaps
Metafiles
Bitmaps are often used for very Bitmaps are often used for very complex images originating in complex images originating in the real world. the real world. Its like the Raster graphics. Its like the vector graphics.
Bitmap images can be created : Manually Algorithmically Bitmaps are often used for images from the real world. Various hardware devices helps to move images from the real world into the computer. Eg. Scanner
A bitmap is rectangular and has a spatial dimension, which is the width and height of the image in pixels.
The spatial dimensions of a bitmap are often referred to as its resolution. Bitmaps are rectangular but computer memory is linear. So how Bitmaps are stored in memory?
Bitmaps also have a color dimension. It is the number of bits required for each pixel and is also called the color depth of the bitmap or the bit-count or the number of bits per pixel (bpp). A bitmap with 1 bit per pixel is called a bilevel or bicolor or monochrome bitmap. Each pixel is either a 0 or a 1. A value of 0 means black, and a 1 means white.
It helps in copying an image from one area of the video display to another. The BLT originated as an assembly language instruction that did memory block transfers. BitBlt function is a pixel mover. BitBlt function transfers pixels from a rectangular area in one device context, called the source, to a rectangular area of the same size in another device context, called the destination.
Syntax:
BitBlt (hdcDst, xDst, yDst, cx, cy, hdcSrc, xSrc, ySrc, dwROP) ;
Destination device context is the window's client area. The device context handle is obtained from the BeginPaint function. The source device context is the application's whole window. This device context handle is obtained from GetWindowDC. dwROP is called the raster operation.
To stretch or compress the size of the image use the StretchBlt function:
StretchBlt (hdcDst, xDst, yDst, cxDst, cyDst,hdcSrc, xSrc, ySrc, cxSrc, cySrc, dwROP) ;
Raster operation inverts the colors of the bitmaps as it is copied. BitBlt and StretchBlt functions perform a bitwise operation between the following three images:
Source Destination Pattern
Raster operations used with BitBlt and StretchBlt involve a combination of these three objects and it results in 256 raster operations.
The logical operation that PatBlt performs on the brush and the destination device context is determined by the dwROP argument.
Windows has supported a GDI bitmap object since version 1.0 . GDI Bitmap Object is now also known as the devicedependent bitmap (DDB). DDB is one of the graphics objects defined in the Windows Graphics Device Interface. A handle to a DDB can be stored in a variable of type HBITMAP. HBITMAP hBitmap ; Can obtain the handle by calling the DDB-creation function: CreateBitmap.
hBitmap = CreateBitmap (cx, cy, cPlanes, cBitsPixel, bits) ;
Creating a DDB
CreateBitmap function allocates and initializes some memory in GDI memory to store information about the bitmap as well as the actual bitmap bits. The memory allocated for the DDB is:
iBitmapBytes = cy * cPlanes * iWidthBytes ;
The pixel bits in DDBs are arranged beginning with the top row.
A memory device context required to use a GDI bitmap object. A memory device context exists only in memory. To create a memory device context: hdcMem = CreateCompatibleDC (hdc) ;