|
Attached is an example (written in VC 6.0 using MFC and using LEAD's API functions) that shows how to load an image into a buffer the developer allocates. The bulk of the code is below:
1. When you call L_CreateBitmap, the last parameter must be the EXACT required size.
L_UINT32 GetRequiredSize(L_INT nWidth, L_INT nHeight, L_INT nBitsPerPixel) { L_INT nSize = 0; BITMAPHANDLE TempBitmap; memset(&TempBitmap, 0, sizeof(TempBitmap)); nRet = L_InitBitmap(&TempBitmap, sizeof(TempBitmap), nWidth, nHeight, nBitsPerPixel); if (nRet == SUCCESS) { nSize = TempBitmap.Size; } return nSize; }
2. When calling LoadFile, you must pass the flags (LOADFILE_STORE | LOADFILE_NOINITBITMAP) like so:
BOOL MyLoadBitmap(L_CHAR *pszFile, pBITMAPHANDLE pBitmap, L_INT nWidth, L_INT nHeight, L_INT nBitsPerPixel) { L_INT nRet; L_INT nSize = 0; L_UCHAR *pData = NULL; if (!pBitmap) return FALSE; nSize = GetRequiredSize(nWidth,nHeight,nBitsPerPixel); if (nSize == 0) return FALSE; pData = (L_UCHAR *)malloc(nSize); if (!pData) return FALSE; nRet = L_CreateBitmap(pBitmap, sizeof(BITMAPHANDLE), TYPE_USER, nWidth, nHeight, nBitsPerPixel, ORDER_BGR, 0, BOTTOM_LEFT, pData, nSize); if (nRet != SUCCESS) { free(pData); return FALSE; } nRet = L_LoadFile(pszFile, pBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, LOADFILE_STORE | LOADFILE_NOINITBITMAP, NULL, NULL, NULL, NULL); return (nRet == SUCCESS); }
Travis Montgomery LEAD Technical Support
|