You are on page 1of 12

There are two methods for storing pictorial information in a Windows program:

Bitmaps
Metafiles

Bitmap vs. Metafile:


Bitmap A bitmap is a two-dimensional rectangular array of bits that correspond to the pixels of an image. Metafile A metafile is a description of a picture rather than a digital representation of it.

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 vs. Metafile (cntd)


Bitmap When stretched or compressed, leads to distortion. Require a large amount of storage space. Copying a bitmap to a video display is usually much Faster. Metafile A metafile can be scaled to almost any size without distortion. Require much less storage space. Rendering a metafile is comparatively slower.

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?

Color and Bitmaps


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.

Additional colors require more bits per pixel.


The number of possible colors is equal to 2bit-count.

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.

Stretching the Bitmap:

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) ;

The Raster Operations

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 Pattern Blt

It uses only a destination device context. Syntax:


PatBlt (hdc, x, y, cx, cy, dwROP) ;

The logical operation that PatBlt performs on the brush and the destination device context is determined by the dwROP argument.

It supports 16 of the raster operations.

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 Bitmap Bits

To set the pixel bits:


SetBitmapBits (hBitmap, cBytes, &bits) ;

To get the pixel bits:


GetBitmapBits (hBitmap, cBytes, &bits) ;

The pixel bits in DDBs are arranged beginning with the top row.

The Memory Device Context

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) ;

You might also like