LBitmapBase::ConvertToDIB

#include "ltwrappr.h

virtual HGLOBAL LBitmapBase::ConvertToDIB(uType)

L_UINT uType;

/* type of DIB */

Converts an LBitmapBase objects 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:

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.

Platforms

Win32, x64.

See Also

Functions:

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

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
#include <io.h>
#include <fcntl.h>
int MySaveFile(HGLOBAL hDIB, L_TCHAR  *pszFileName) 
{
   
   HANDLE fp;
   unsigned char *pDIB; 
   BITMAPFILEHEADER bfh; 
   PBITMAPINFOHEADER pbih; 
   SIZE_T nDIBsize; 
   DWORD wWrittenBytes;
   nDIBsize = GlobalSize(hDIB); 
   bfh.bfType        = 0x4d42; //"BM";
   bfh.bfSize        = (DWORD) (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); 
   
   fp = CreateFile(pszFileName, GENERIC_ALL, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
   if (fp == 0) 
      return FALSE; 
     WriteFile(fp, &bfh,(DWORD)(sizeof(BITMAPFILEHEADER)), &wWrittenBytes, NULL);
     WriteFile(fp, pDIB,(DWORD)(nDIBsize), &wWrittenBytes, NULL); 
     CloseHandle(fp);
   GlobalUnlock(hDIB); 
   return TRUE; 
}
L_INT LBitmapBase__ConvertToDIBExample(LBitmapBase * pBitmap, L_TCHAR *pszFileName) 
{
   UNREFERENCED_PARAMETER(pszFileName);
   L_INT nRet;
   HGLOBAL hDIB; 
   hDIB = pBitmap->ConvertToDIB(DIB_BITMAPV5HEADER); 
   nRet =MySaveFile(hDIB, MAKE_IMAGE_PATH(TEXT("dib3.bmp")));
   if(nRet !=SUCCESS)
      return nRet;
   GlobalFree(hDIB); 
   return SUCCESS;
}