L_SetBitmapDataPointer - Raster Imaging C API Help


#include "l_bitmap.h"

L_LTKRN_API L_INT L_SetBitmapDataPointer(pBitmap, pData, dwSize)


pointer to the bitmap handle

L_UCHAR *pData;

data pointer

L_SIZE_T dwSize;

size of the data buffer pointed to by pData

Sets the data pointer for the specified bitmap to the specified data pointer pData.




Pointer to the bitmap handle that references the bitmap whose data pointer will be set.


Data pointer used to set the specified bitmaps data pointer.


Size of the data buffer pointed to by pData.



The function was successful.

< 1

An error occurred. Refer to Return Codes.


This function can be used to change the data pointer of a bitmap that was created by L_CreateBitmap, or allocated by L_AllocateBitmap, with memory type TYPE_USER. The data pointer to of the bitmap is set to the data pointer passed in through pData.

You are responsible for managing the image data. L_FreeBitmap will not free pData.

The memory buffer pointed to by pData must be valid when the bitmap is being used. If you free a memory buffer that is referenced by a bitmap, you will get access violations when you try to use that bitmap.

If you pass NULL for pData, the bitmap has no bitmap data. You should not try to use a bitmap that has no data pointer.

Note: To calculate the correct size for a single row of image data:


(((Width * BitsPerPixel) + 31) >> 3)) &~3


(((Width * BitsPerPixel) + 7) / 8)

Required DLLs and Libraries


For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.


Win32, x64, Linux.

See Also


L_AllocateBitmap, L_CreateBitmap


Raster Image Functions: Creating and Deleting Images


Please note that you need to free the memory allocated for the bitmap and the bitmap data using the following:

L_INT SetBitmapDataPointerExample(pBITMAPHANDLE pBitmap) 
   // allocate a buffer large enough to hold two copies of the image 
   L_UCHAR* pBuffer = (L_UCHAR*)GlobalAllocPtr(GMEM_MOVEABLE, pBitmap->Size * 2); 
   L_INT    i; 
   L_INT    nRet; 
   // lock the bitmap 
   // loop and get the flipped and normal versions of the image into pBuffer 
   for(i = 0; i < pBitmap->Height; i++) 
      nRet =(L_INT) L_GetBitmapRow(pBitmap,  
                                    pBuffer + i * pBitmap->BytesPerLine, 
                                    pBitmap->ViewPerspective == TOP_LEFT ? pBitmap->Height - i - 1 : i,  
      if(nRet < 1) 
         return nRet; 
      memcpy( pBuffer + pBitmap->Size + (pBitmap->Height - i - 1) * pBitmap->BytesPerLine,  
               pBuffer + i * pBitmap->BytesPerLine,  
   //unlock the bitmap 
   // free the original image. Note that it is assumed that the image was 24 bit 
   // for simplicity, so that it is not necessary to pass an array of palette entries to L_CreateBitmap 
   // For color images, you would have to get the palette entries and pass them instead of NULL 
  // this sets the image to be the flipped version 
   if((nRet = L_CreateBitmap(pBitmap, sizeof(BITMAPHANDLE), 
                  pBitmap->Width, pBitmap->Height, pBitmap->BitsPerPixel,  
                  pBitmap->Order, NULL,  
                  pBuffer, pBitmap->Size)) == SUCCESS) 
      MessageBox( NULL, TEXT("The image is flipped"), TEXT(""), MB_OK); 
      // this sets the image to be the non-flipped version 
      return L_SetBitmapDataPointer(pBitmap, pBuffer + pBitmap->Size, pBitmap->Size); 
   return nRet; 

Help Version 20.0.2018.7.30
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help