Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

Windows Embedded 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 Embedded CE contains many functions you can use with DirectX.

Code Example

The following code example combines Windows Embedded CE and DirectX functions to load a DIB onto a DirectX surface.

Note:
To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.
Copy Code
extern C IDirectDrawSurface * DDLoadBitmap(IDirectDraw *pdd, 
	LPCSTR szBitmap, int dx, int dy) 
{ 
	HBITMAP			 hbm; 
	BITMAP			bm; 
	DDSURFACEDESC	 ddsd; 
	IDirectDrawSurface *pdds; 
 
	// 
	//  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.