LEADTOOLS Support
Imaging
Imaging SDK Examples
How to load/decompress a file into your own buffer
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Thursday, May 18, 2006 10:29:03 AM(UTC)
Groups: Registered, Tech Support
Posts: 207
Was thanked: 3 time(s) in 3 post(s)
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
Senior Sales Engineer
#2
Posted
:
Wednesday, May 21, 2008 1:19:00 PM(UTC)
Groups: Registered
Posts: 5
That seems to work fine most of the time, but there are cases when it doesn't work. How can I make this code work when there is a different view perspective set in the file that I'm loading?
For example, the attached file has a view perspective of RIGHT_TOP which makes the L_LoadFile call fail. I need to be able to handle this case. What should I do?
#3
Posted
:
Thursday, May 22, 2008 10:36:17 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 764
You should set the ELO_IGNOREVIEWPERSPECTIVE flag in the LOADFILEOPTION.Flags property. If you use this for both the call to L_FileInfo and L_LoadFile, then it should work.
Though not necessary for L_LoadFile to return SUCCESS, I would also suggest using the view perspective reported by L_FileInfo as well. Here's the modified code snippet:
void CTutorDlg::OnLoad()
{
L_INT nRet;
L_INT nSize = 0;
L_UCHAR *pData = NULL;
BITMAPHANDLE Bitmap;
FILEINFO fi;
L_INT nWidth, nHeight, nBitsPerPixel, nViewPerspective;
LOADFILEOPTION lfo;
L_GetDefaultLoadFileOption(&lfo, sizeof(LOADFILEOPTION));
lfo.Flags = ELO_IGNOREVIEWPERSPECTIVE;
nRet = L_FileInfo("Test.jpg", &fi, sizeof(FILEINFO), 0, &lfo);
nWidth = fi.Width;
nHeight = fi.Height;
nBitsPerPixel = fi.BitsPerPixel;
nViewPerspective = fi.ViewPerspective;
nSize = GetRequiredSize(nWidth,nHeight,nBitsPerPixel);
if (nSize == 0)
return;
pData = (L_UCHAR *)malloc(nSize);
if (!pData)
return;
nRet = L_CreateBitmap(&Bitmap, sizeof(BITMAPHANDLE), TYPE_USER, nWidth, nHeight, nBitsPerPixel, ORDER_BGR, 0, nViewPerspective, pData, nSize);
if (nRet != SUCCESS)
{
free(pData);
return;
}
nRet = L_LoadFile("Test.jpg", &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR,
LOADFILE_STORE | LOADFILE_NOINITBITMAP, NULL, NULL, &lfo, NULL);
return;
}
LEADTOOLS Support
Imaging
Imaging SDK Examples
How to load/decompress a file into your own buffer
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.