Device-Independent Bitmaps (Windows CE 5.0)

Send Feedback

Windows CE and DirectX® use the device-independent bitmap (DIB) as their native graphics file format.

A DIB is a file that contains information describing the following:

  • An image's dimensions
  • The number of colors the image uses
  • Values describing the colors used
  • Data that describes each pixel

A DIB also contains lesser-used parameters, like

  • Information about file compression
  • Significant colors (if all are not used)
  • Physical dimensions of the image (in case it will end up in print)

DIB files usually have the .bmp file extension, although they can use a .dib extension.

Because the DIB is so pervasive in Windows programming, Windows CE contains many functions you can use with DirectX.

For example, the following application-defined function combines Windows CE and DirectX functions to load a DIB onto a DirectX surface.

extern C IDirectDrawSurface * DDLoadBitmap(IDirectDraw *pdd, 
    LPCSTR szBitmap, int dx, int dy) 
{ 
    HBITMAP             hbm; 
    BITMAP              bm; 
    DDSURFACEDESC       ddsd; 
    IDirectDrawSurface *pdds; 
 
    // 
    //  This is the Windows CE part. 
    //  Try to load the bitmap as a resource.
    // 
    hbm = (HBITMAP)LoadImage(
            GetModuleHandle(NULL), szBitmap, 
            IMAGE_BITMAP, dx, dy, LR_CREATEDIBSECTION); 
 
    if (hbm == NULL) 
        return NULL; 
 
    // 
    // Get the size of the bitmap. 
    // 
    GetObject(hbm, sizeof(bm), &bm); 
 
    // 
    // Now, return to DirectX function calls. 
    // Create a DirectDrawSurface for this bitmap. 
    // 
    memset(&ddsd, 0, sizeof(ddsd)); 
    ddsd.dwSize = sizeof(ddsd); 
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH; 
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; 
    ddsd.dwWidth = bm.bmWidth; 
    ddsd.dwHeight = bm.bmHeight; 
 
    if (pdd->CreateSurface(&ddsd, &pdds, NULL) != DD_OK) 
        return NULL; 
 
    DDCopyBitmap(pdds, hbm, 0, 0, 0, 0); 
 
    DeleteObject(hbm); 
 
    return pdds; 
} 

For more detailed information about DIB files, see Using Bitmaps.

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.