GetDIB2 example for C++ 5.0 and later
//This example takes a LEADRasterView1 control (m_LEADRasterView1) with an image,
//converts it to a V5 DIB and writes out the DIB as a bitmap file
#include <io.h>
#include <fcntl.h>
HGLOBAL hDIB;
int fp, nSize;
unsigned char *pDIB;
BITMAPFILEHEADER bfh;
PBITMAPINFOHEADER pbih;
int nDIBsize;
hDIB = (HGLOBAL)m_LEADRasterView1.GetRaster().GetDIB2 (DIB_BITMAPV5HEADER);
nDIBsize = GlobalSize(hDIB);
bfh.bfType = 0x4d42; //"BM";
bfh.bfSize = sizeof(BITMAPFILEHEADER) + nDIBsize;
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
pDIB = (unsigned char*)::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 = _tfopen(TEXT("c:\\temp\\dib.bmp"), _O_RDWR | _O_CREAT | _O_BINARY, 0);//_S_IREAD | _S_IWRITE );
if (fp == 0)
return;
nSize = _write( fp, &bfh, sizeof(BITMAPFILEHEADER));
nSize = _write( fp, pDIB, nDIBsize);
_close(fp);
GlobalUnlock(hDIB);
GlobalFree(hDIB);
return;