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 : Tuesday, December 27, 2016 9:58:43 AM(UTC)
Mudassir

Groups: Registered
Posts: 3

Thanks: 1 times

Hi,

I have a System.Drawing.Bitmap object in my application that's being created by another third party component.

I want to convert this managed Bitmap object to the LeadTools native bitmap format without saving the managed Bitmap on the disk, so that it can be used with another component of the application.

At the moment, I'm creating the LeadTools native bitmap by saving managed Bitmap on the disk and then passing the temp file name to the L_LoadBitmap API, which is not a performance efficient solution

Does LeadTools supports a better way to convert the Managed Bitmap to the native bitmap or image file in memory?

Thank you,
Mudassir


 

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 : Friday, December 30, 2016 1:50:50 PM(UTC)

Hadi  
Hadi

Groups: Manager, Tech Support, Administrators
Posts: 218

Was thanked: 12 time(s) in 12 post(s)

You can use the LEADTOOLS RasterImageConverter as seen in this link:

The LEADTOOLS RasterImage class provides platform-independent representation of an image. It serves as a working area for image manipulation and conversion. LEADTOOLS functions use this class for accessing the image in memory and for maintaining the characteristics of the image. This class contains the functionality for converting a LEADTOOLS Leadtools.RasterImage to and from a Windows GDI or GDI+ image objects.

Specifically, you can use the 'ConvertFromImage' method:

https://www.leadtools.co...er-convertfromimage.html

Edited by user Wednesday, February 10, 2021 10:20:52 AM(UTC)  | Reason: Not specified

Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.

LEAD Logo
 
#3 Posted : Friday, January 6, 2017 3:08:57 PM(UTC)
Mudassir

Groups: Registered
Posts: 3

Thanks: 1 times

I guess I'm missing something here...

What I understood is that this solution converts to the RasterImage which is another managed object. Is there a way to get the "file in memory" handle from it?

I'm looking for a way to convert the GDI+ Image either to native bitmap (so that I can use BITMAPHANDLE) or native "file in memory" handle.

Thanks!
Mudassir

Edited by moderator Tuesday, February 16, 2021 11:04:34 AM(UTC)  | Reason: Not specified

 
#4 Posted : Thursday, January 12, 2017 5:35:33 PM(UTC)

Hadi  
Hadi

Groups: Manager, Tech Support, Administrators
Posts: 218

Was thanked: 12 time(s) in 12 post(s)

You can check out the L_LoadBitmapMemory and the L_LoadMemory functions:

https://www.leadtools.co.../l_loadbitmapmemory.html
https://www.leadtools.co...in/api/l_loadmemory.html

Here's an example of using L_LoadBitmapMemory:

Code:
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
L_LTFILTEX_API  L_INT SaveBitmapMemoryExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle for the final image */
   BITMAPHANDLE TmpBitmap;    /* Bitmap handle for the initial image */
   HGLOBAL hFileInMemory = NULL;     /* Memory handle */
   L_SIZE_T uMemSize;   /* Size of the data in memory */
   L_UCHAR  *pData;     /* Pointer to the data in memory */

   /* Load a bitmap at its own bits per pixel  */
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Save the image as a CMP file in memory */
   nRet = L_SaveBitmapMemory(&hFileInMemory, &TmpBitmap, FILE_CMP, 24, QS, &uMemSize, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Free the temporary bitmap */
   if(TmpBitmap.Flags.Allocated)  
      L_FreeBitmap(&TmpBitmap);

   /* Get the pointer to the memory-resident file */
   pData = (L_UCHAR  *) GlobalLock (hFileInMemory);

   /* Load the new bitmap from memory at its own bits per pixel  */
   nRet = L_LoadBitmapMemory (pData, &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, uMemSize, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Clean up */
   GlobalUnlock (hFileInMemory);
   GlobalFree (hFileInMemory);
   L_FreeBitmap(&LeadBitmap);
   return SUCCESS;
}


Here's an example of using L_LoadMemory:

Code:
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
/* Structure used for the callback function's user data */
typedef struct tagIMAGECBPARM
{
   HWND hwnd;     /* Current window                        */
   HDC  hdc;      /* Device context for the current window */
} IMAGECBPARM;

static L_INT EXT_CALLBACK LoadImageCB(pFILEINFO     pFileInfo,
                                      pBITMAPHANDLE pBitmap,
                                      L_UCHAR     * pBuffer,
                                      L_UINT        uFlags,
                                      L_INT         nRow,
                                      L_INT         nLines,
                                      L_VOID      * pUserData)
{
   static RECT rLeadSource;
   static RECT rLeadDest;
   IMAGECBPARM *pData = (IMAGECBPARM*)pUserData;

   /* If this is the first call (row 0), select and realize the palette */
   if((uFlags & FILEREAD_FIRSTPASS) && (uFlags & FILEREAD_FIRSTROW) )
   {
      /* Set the source rectangle to use the whole bitmap */
      SetRect(&rLeadSource, 0, 0, pFileInfo->Width, pFileInfo->Height);
      /* Set the dest rectangle to use the whole client area */
      GetClientRect(pData->hwnd, &rLeadDest);
   }

   /* Paint the buffer to the specified device context */
   L_PaintDCBuffer( pData->hdc, /* Device context - from function parameter */
                    pBitmap, /* Bitmap handle - from function parameter */
                    &rLeadSource, /* Source rect - set globally in WM_CREATE */
                    &rLeadSource, /* Source clip rect - same as source rect */
                    &rLeadDest, /* Destination rect - set globally in WM_CREATE */
                    &rLeadDest, /* Destination clip rect - same as destination rect */
                    SRCCOPY, /* ROP code for normal painting */ 
                    pBuffer, /* Input buffer - from function parameter */ 
                    nRow, /* First row in the buffer - from function parameter */ 
                   (uFlags & FILEREAD_COMPRESSED) ? -nLines : nLines );
   return( SUCCESS );
}

L_LTFILTEX_API  L_INT LoadMemoryExample(HWND hWnd)
{
   L_INT nRet; 
   BITMAPHANDLE TmpBitmap;       /* Bitmap handle for the initial image */
   HGLOBAL hFileInMemory=NULL;   /* Memory handle                       */
   L_SIZE_T uMemSize;            /* Size of the data in memory          */
   L_UCHAR *pData;               /* Pointer to the data in memory       */
   static IMAGECBPARM UserData;  /* Structure used for the callback function's user data */
   FILEREADCALLBACK lpfnCallBack;

   /* Load a bitmap at its own bits per pixel  */
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Save the image as a CMP file in memory */
   nRet = L_SaveBitmapMemory(&hFileInMemory, &TmpBitmap, FILE_CMP, 24, QS, &uMemSize, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Free the temporary bitmap */
   L_FreeBitmap(&TmpBitmap);

   /* Get the pointer to the memory-resident file */
   pData = (L_UCHAR *) GlobalLock (hFileInMemory);

   /* Set the user data used for the callback in the nRet = L_LoadFile function */
   UserData.hwnd = hWnd;         /* Current window */
   UserData.hdc = GetDC( hWnd ); /* Device context for the current window */

   /* Set the callback function for the L_LoadFile function.*/
   lpfnCallBack = (FILEREADCALLBACK)LoadImageCB;

   /* Load the file, calling lpfnCallBack to paint the bitmap. */
   nRet = L_LoadMemory(pData,
                      &TmpBitmap, sizeof(BITMAPHANDLE),
                      0,
                      ORDER_BGR,
                      LOADFILE_ALLOCATE |  LOADFILE_STORE,
                      lpfnCallBack,
                      &UserData,
                      uMemSize,
                      NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Clean up */
   GlobalUnlock (hFileInMemory);
   GlobalFree (hFileInMemory);
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &TmpBitmap, FILE_BMP, 24, 0, NULL);
   L_FreeBitmap(&TmpBitmap);

   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.

LEAD Logo
thanks 1 user thanked Hadi for this useful post.
Mudassir on 1/13/2017(UTC)
 
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-2024, Yet Another Forum.NET
This page was generated in 0.081 seconds.