L_SetBitmapDataPointer

#include "l_bitmap.h"

L_LTKRN_API L_INT L_SetBitmapDataPointer(pBitmap, pData, dwSize)

pBITMAPHANDLE pBitmap;

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.

Parameter

Description

pBitmap

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

pData

Data pointer used to set the specified bitmaps data pointer.

dwSize

Size of the data buffer pointed to by pData.

Returns

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:

Windows:

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

Linux:

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

Required DLLs and Libraries

LTKRN

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

Platforms

Win32, x64, Linux.

See Also

Functions:

L_AllocateBitmap, L_CreateBitmap

Topics:

Raster Image Functions: Creating and Deleting Images

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 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help