bitmaps and bitblts

Upload: prashant-bajpai

Post on 04-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Bitmaps and Bitblts

    1/12

    There are two methods for storing pictorial information in aWindows program:

    Bitmaps

    Metafiles

    Bitmap vs. Metafile:

    Bitmap Metafile

    A bitmap is a two-dimensionalrectangular array of bits thatcorrespond to the pixels of animage.

    A metafile is a description of apicture rather than a digitalrepresentation of it.

    Bitmaps are often used for verycomplex images originating inthe real world.

    Bitmaps are often used for verycomplex images originating inthe real world.

    Its like the Raster graphics. Its like the vector graphics.

  • 7/29/2019 Bitmaps and Bitblts

    2/12

    Bitmap vs. Metafile (cntd)

    Bitmap Metafile

    When stretched orcompressed, leads todistortion.

    A metafile can be scaledto almost any size withoutdistortion.

    Require a large amountof storage space.

    Require much lessstorage space.

    Copying a bitmap to avideo display is usuallymuch Faster.

    Rendering a metafile iscomparatively slower.

    Bitmap images can be created :ManuallyAlgorithmically

    Bitmaps are often used for images from the real world.

    Various hardware devices helps to move images from the realworld into the computer. Eg. Scanner

  • 7/29/2019 Bitmaps and Bitblts

    3/12

    A bitmap is rectangular and has a spatial dimension, which isthe width and height of the image in pixels.

    The spatial dimensions of a bitmap are often referred to as itsresolution.

    Bitmaps are rectangular but computer memory is linear. Sohow Bitmaps are stored in memory?

  • 7/29/2019 Bitmaps and Bitblts

    4/12

    Color and Bitmaps

    Bitmaps also have a color dimension.

    It is the number of bits required for each pixel and is alsocalled the color depth of the bitmap or the bit-count or thenumber of bits per pixel (bpp).

    A bitmap with 1 bit per pixel is called a bilevel orbicolor ormonochrome bitmap.

    Each pixel is either a 0 or a 1. A value of 0 means black, anda 1 means white.

    Additional colors require more bits per pixel.

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

  • 7/29/2019 Bitmaps and Bitblts

    5/12

    It helps in copying an image from one area of the videodisplay to another.

    The BLT originated as an assembly language instruction thatdid memory block transfers.

    BitBlt function is a pixel mover.

    BitBlt function transfers pixels from a rectangular area in onedevice context, called the source, to a rectangular area ofthe same size in another device context, called thedestination.

  • 7/29/2019 Bitmaps and Bitblts

    6/12

    Syntax:

    Destination device context is the window's client area. Thedevice context handle is obtained from the BeginPaintfunction.

    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:

    BitBlt (hdcDst, xDst, yDst, cx, cy, hdcSrc, xSrc, ySrc, dwROP) ;

    StretchBlt (hdcDst, xDst, yDst, cxDst, cyDst,hdcSrc, xSrc, ySrc,cxSrc, cySrc, dwROP) ;

  • 7/29/2019 Bitmaps and Bitblts

    7/12

    The Raster Operations

    Raster operation inverts the colors of the bitmaps as it iscopied.

    BitBlt and StretchBlt functions perform a bitwise operationbetween 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 rasteroperations.

  • 7/29/2019 Bitmaps and Bitblts

    8/12

    The Pattern Blt

    It uses only a destination device context.

    Syntax:

    The logical operation that PatBlt performs on the brush andthe destination device context is determined by the dwROPargument.

    It supports 16 of the raster operations.

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

  • 7/29/2019 Bitmaps and Bitblts

    9/12

    Windows has supported a GDI bitmap object since version1.0 .

    GDI Bitmap Object is now also known as the device-dependent bitmap (DDB).

    Creating a 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 typeHBITMAP.

    HBITMAP hBitmap ;

    Can obtain the handle by calling the DDB-creation function:CreateBitmap.

    hBitmap = CreateBitmap (cx, cy, cPlanes, cBitsPixel, bits) ;

  • 7/29/2019 Bitmaps and Bitblts

    10/12

    CreateBitmap function allocates and initializes some memory inGDI memory to store information about the bitmap as well asthe actual bitmap bits.

    The memory allocated for the DDB is:iBitmapBytes = cy * cPlanes * iWidthBytes ;

    The Bitmap Bits

    To set the pixel bits:

    To get the pixel bits:

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

    GetBitmapBits (hBitmap, cBytes, &bits) ;

    SetBitmapBits (hBitmap, cBytes, &bits) ;

  • 7/29/2019 Bitmaps and Bitblts

    11/12

    The Memory Device Context

    A memory device context required to use a GDI bitmapobject.

    A memory device context exists only in memory.

    To create a memory device context:

    hdcMem = CreateCompatibleDC (hdc) ;

  • 7/29/2019 Bitmaps and Bitblts

    12/12