L_ConvertToDDB

#include "l_bitmap.h"

L_LTDIS_API L_HBITMAP L_ConvertToDDB(hDC, pBitmap)

Converts a LEAD Technologies bitmap into a Windows device dependent bitmap (DDB). When this function is completed, there are two copies of the image in memory: the DDB and the original LEAD bitmap. Freeing one will not affect the other.

Parameters

L_HDC hDC

Handle to the device responsible for the conversion. The mapping mode of the device context must be MM_TEXT.

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap to copy.

Returns

This function returns a handle to the DDB, or it returns a NULL if there is an error.

Comments

This function allocates a DDB bitmap and copies the LEAD bitmap to the DDB.

If this function fails, the return value is a NULL HBITMAP.  This can happen if the image is too large for the Windows C API functions that LEADTOOLS uses internally.  To get more information about why the Windows C API functions may have failed, you can use the Windows C API GetLastError.

/* Change the initial bitmap to a DDB */ 
hDDB = L_ChangeToDDB( hDC, &Bitmap ); 
if(!hDDB) 
{ 
   DWORD dwRet = GetLastError(); 
   /* process the error code here */ 
} 

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

For complete sample code, refer to the DIBDDB example. This example loads a bitmap, converts it to a DDB, then converts the DDB back to a bitmap.

L_INT ConvertToDDBExample(L_HWND          hWnd,pBITMAPHANDLE pLeadBitmap) 
{ 
   L_INT nRet; 
   BITMAPHANDLE   TmpBitmap;        /* Bitmap handle for the initial image */ 
   HBITMAP        hDDB;             /* Handle for the DDB */ 
   HPALETTE       hPalette;         /* Palette handle */ 
   HPALETTE       hpalSave = NULL;  /* Saved palette handle */ 
   HDC            hDC;              /* Handle to the device context for the current window */ 
 
   /* Get the device context for the current window */ 
   hDC = GetDC( hWnd ); 
   /* Load a bitmap, keeping 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; 
   hPalette = L_CreatePaintPalette(hDC, &TmpBitmap); 
   if (hPalette) 
   { 
      hpalSave = SelectPalette(hDC, hPalette, FALSE); 
      RealizePalette(hDC); 
   } 
   /* Convert the initial bitmap to a DDB */ 
   hDDB = L_ConvertToDDB( hDC, &TmpBitmap ); 
   if (hPalette) 
      SelectPalette(hDC, hpalSave, FALSE); 
   /* Free the initial bitmap */ 
   L_FreeBitmap(&TmpBitmap); 
   /* Convert the DDB to create a new LEAD bitmap */ 
   nRet = L_ConvertFromDDB(hDC, pLeadBitmap, sizeof(BITMAPHANDLE), hDDB, hPalette); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Clean up */ 
   ReleaseDC( hWnd, hDC ); 
   DeleteObject(hDDB); 
   DeleteObject(hPalette); 
   return SUCCESS; 
} 

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help