LBitmapBase::SetDataPointer (original) (raw)

Summary

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

Syntax

#include "ltwrappr.h"

virtual L_INT LBitmapBase::SetDataPointer(pData, dwSize)

Parameters

L_UCHAR *pData

Data pointer used to set the bitmaps data pointer.

L_UINT32 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 LBitmapBase::CreateBitmap, or allocated by LBitmapBase::Allocate, 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. LBitmapBase::Free 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

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

#define BITMAP_WIDTH 256 #define BITMAP_HEIGHT 256 L_INT LBitmapBase__SetDataPointerExample(HWND hWnd) { UNREFERENCED_PARAMETER(hWnd); L_INT nRet; HGLOBAL hGlobal1, hGlobal2; L_UCHAR *pBuffer1, *pBuffer2; LBitmapBase BitmapBase; //pBuffer1 points to raw data with 256 shades of red //pBuffer2 points to raw data with 256 shades of green hGlobal1 = GlobalAlloc(GMEM_MOVEABLE, BITMAP_WIDTH * BITMAP_HEIGHT * 3); pBuffer1 = (L_UCHAR*)GlobalLock(hGlobal1); hGlobal2 = GlobalAlloc(GMEM_MOVEABLE, BITMAP_WIDTH * BITMAP_HEIGHT * 3); pBuffer2 = (L_UCHAR*)GlobalLock(hGlobal2); L_INT iCol, iRow, iCounter; iCounter = 0; for(iCol = 0; iCol < BITMAP_WIDTH; iCol++) for (iRow=0; iRow < BITMAP_HEIGHT; iRow++) { pBuffer1[iCounter + 0] = 0; //Blue pBuffer1[iCounter + 1] = 0; //Green pBuffer1[iCounter + 2] = (L_UCHAR)iCol; //Red pBuffer2[iCounter + 0] = 0; //Blue pBuffer2[iCounter + 1] = (L_UCHAR) iCol; //Green pBuffer2[iCounter + 2] = 0; //Red iCounter = iCounter + 3; } // this sets the image to be pBuffer1 nRet =BitmapBase.Create( BITMAP_WIDTH, BITMAP_HEIGHT, 24, ORDER_BGR, NULL, TOP_LEFT, TYPE_USER, (L_UCHAR *)pBuffer1, BITMAP_WIDTH * BITMAP_HEIGHT * 3); if(nRet !=SUCCESS) return nRet; nRet =BitmapBase.Save(MAKE_IMAGE_PATH(TEXT("Test1.bmp")), FILE_BMP, 24,2,0,NULL); if(nRet !=SUCCESS) return nRet; nRet =BitmapBase.SetDataPointer(pBuffer2, BITMAP_WIDTH * BITMAP_HEIGHT * 3); if(nRet !=SUCCESS) return nRet; nRet =BitmapBase.Save(MAKE_IMAGE_PATH(TEXT("Test2.bmp")), FILE_BMP, 24,2,0,NULL); if(nRet !=SUCCESS) return nRet; return SUCCESS; }

LEADTOOLS Raster Imaging C++ Class Library Help