L_ConvertToDIB

#include "l_bitmap.h"

HGLOBAL EXT_FUNCTION L_ConvertToDIB(pBitmap, uType)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_UINT uType;

/* type of DIB */

Converts a LEAD Technologies 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

pBitmap

Pointer to the bitmap handle referencing the bitmap to change.

uType

Flag that indicates the 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

This function allocates a DIB bitmap and copies the LEAD bitmap to the DIB.

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.

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

Required DLLs and Libraries

LTKRN

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

Windows 95 / 98 / Me, Windows 2000 / XP, Windows CE.

See Also

Functions:

L_ConvertFromDDB, L_ConvertFromDIB,

 

L_ConvertToDDB, L_ChangeFromDDB,

 

L_ChangeFromDIB, L_ChangeToDDB,

 

L_ChangeToDIB

Topics:

Raster Image Functions: Creation, Deletion, and Copying

 

Using DIBs, DDBs, and the Clipboard

Example

For complete sample code, refer to the DIBDDB 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(pBITMAPHANDLE pBitmap, L_TCHAR L_FAR* pszFileName)
{
   HGLOBAL hDIB;
   hDIB = L_ConvertToDIB(pBitmap, sizeof(BITMAPHANDLE));
   MySaveFile(hDIB, TEXT("e:\\erase\\dib3.bmp"));
   GlobalFree(hDIB);
}