Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, May 18, 2006 10:29:03 AM(UTC)

Travis  
Travis

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);
}

File Attachment(s):
API - V14 - Load Image into user buffer.zip (89kb) downloaded 48 time(s).
Travis Montgomery
Senior Sales Engineer
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, May 21, 2008 1:19:00 PM(UTC)

DCurtis  
DCurtis

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?
File Attachment(s):
ViewPerspective.jpg (3,950kb) downloaded 48 time(s).
 
#3 Posted : Thursday, May 22, 2008 10:36:17 AM(UTC)

GregR  
GregR

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;
}

 
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.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.211 seconds.