L_SetBitmapDataPointer

Summary

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

Syntax

#include "l_bitmap.h"

L_LTKRN_API L_INT L_SetBitmapDataPointer(pBitmap, pData, dwSize)

Parameters

pBITMAPHANDLE pBitmap

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

L_UCHAR *pData

Data pointer used to set the specified bitmaps data pointer.

L_SIZE_T dwSize

Size of the data buffer pointed to by pData.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

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:

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

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 
   L_AccessBitmap(pBitmap); 
 
   // 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,  
                                    pBitmap->BytesPerLine); 
      if(nRet < 1) 
         return nRet; 
      memcpy( pBuffer + pBitmap->Size + (pBitmap->Height - i - 1) * pBitmap->BytesPerLine,  
               pBuffer + i * pBitmap->BytesPerLine,  
               pBitmap->BytesPerLine); 
   } 
 
   //unlock the bitmap 
   L_ReleaseBitmap(pBitmap); 
 
   // 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 
   L_FreeBitmap(pBitmap); 
 
  // this sets the image to be the flipped version 
   if((nRet = L_CreateBitmap(pBitmap, sizeof(BITMAPHANDLE), 
                  TYPE_USER,  
                  pBitmap->Width, pBitmap->Height, pBitmap->BitsPerPixel,  
                  pBitmap->Order, NULL,  
                  TOP_LEFT,  
                  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 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.