LBitmapBase::ConvertToDIB

#include "ltwrappr.h

virtual HGLOBAL LBitmapBase::ConvertToDIB(uType)

L_UINT uType;

/* type of DIB */

Converts an LBitmapBase object’s bitmap into a Windows device independent bitmap (DIB). When this function is completed, there are two copies of the image in memory: the DIB and the original LEAD bitmap. Freeing one will not affect the other.

Parameter

Description

uType

Type of DIB to create. Possible values are:

 

Value

Meaning

 

DIB_BITMAPINFOHEADER

[0] DIB that uses a BITMAPINFOHEADER

 

DIB_BITMAPV4HEADER

[1] DIB that uses a BITMAPV4HEADER. (Introduced in Windows 95 and Windows NT 4.0)

 

DIB_BITMAPV5HEADER

[2] DIB that uses a BITMAPV5HEADER (Introduced in Windows 2000 and Windows 98)

Returns

This function will return a handle to a DIB.

Comments

Call this function to get a device independent bitmap (DIB) copy from class object's bitmap.

When you no longer need the DIB, you can free it using the Windows GlobalFree function.

A DIB consists of one of the following:

image\sqrblit.gif a BITMAPFILEHEADER,

image\sqrblit.gif a BITMAPV4HEADER (introduced in Windows 95 and Windows NT 4.0),

image\sqrblit.gif or a BITMAPV5HEADER (introduced in Windows 2000 and Windows 98),

followed by a color table and then the bitmap data. The resulting DIB type is determined by the value of the uType flag.

The orientation of the image and color order will depend on how the image was loaded into the LEAD bitmap.

If you want to load another image using the same bitmap handle, you must initialize the bitmap handle again.

Required DLLs and Libraries

LTDIS
LTFIL

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Elements:

LBitmapBase::ConvertFromDIB, LBitmapBase::ConvertToDDB, LBitmapBase::ConvertFromDDB, Class Members

Topics:

Raster Image Functions: Creation, Deletion, and Copying

 

Using DIBs, DDBs, and the Clipboard

Example

//This example takes a LEAD bitmap, converts it to a V5 DIB and writes
//out the DIB as a bitmap file
#include <io.h>
#include <fcntl.h>


int MySaveFile(HGLOBAL hDIB, L_TCHAR L_FAR *pszFileName) 
{
   int fp, nSize; 
   unsigned char *pDIB; 
   BITMAPFILEHEADER bfh; 
   PBITMAPINFOHEADER pbih; 
   int nDIBsize; 

   nDIBsize = GlobalSize(hDIB); 

   bfh.bfType        = 0x4d42; //"BM";
   bfh.bfSize        =  sizeof(BITMAPFILEHEADER) + nDIBsize; 
   bfh.bfReserved1   = 0; 
   bfh.bfReserved2   = 0; 

   pDIB = (L_UCHAR *)GlobalLock(hDIB); 
   pbih = (PBITMAPINFOHEADER)pDIB; 

   // Compute the offset to the array of color indices. 
   bfh.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + 
                    pbih->biSize + pbih->biClrUsed  * sizeof (RGBQUAD); 
   
#ifdef UNICODE

   fp = _wopen(pszFileName, _O_RDWR | _O_CREAT | _O_BINARY,  0);//_S_IREAD | _S_IWRITE ); 

#else

   fp = _open(pszFileName, _O_RDWR | _O_CREAT | _O_BINARY,  0);//_S_IREAD | _S_IWRITE ); 

#endif

   if (fp == 0) 
      return FALSE; 
   
   nSize =  _write( fp, &bfh, sizeof(BITMAPFILEHEADER)); 
   nSize =  _write( fp, pDIB, nDIBsize); 
   _close(fp); 

   GlobalUnlock(hDIB); 
   return TRUE; 
}

L_VOID ExampleConvertToDIB(LBitmapBase * pBitmap, L_TCHAR *pszFileName) 
{
   HGLOBAL hDIB; 
   hDIB = pBitmap->ConvertToDIB(DIB_BITMAPV5HEADER); 
   MySaveFile(hDIB, TEXT("e:\\erase\\dib3.bmp"));
   GlobalFree(hDIB); 
}