Board index » cppbuilder » CreateBitmap error

CreateBitmap error


2005-11-23 10:11:40 PM
cppbuilder88
Hi,
I've a problem using the following code:
HBITMAP hBmp = CreateBitmap (
imageData.getWidth(), // bitmap width, in pixels
imageData.getHeight(), // bitmap height, in pixels
1, // number of color planes used by device
imageData.getFormat(), // number of bits required to identify a
color
imageData.getBytes() // return a pointer to the array
containing color data
);
if (hBmp == NULL)
throw Exception("CreateBitmap error! code=" +
AnsiString(GetLastError()));
Picture->Bitmap->Handle = hBmp; //Show the bitmap
imageData is a custom object that handles the array of bytes and some
other information about the image.
After some executions of the code CreateBitmap fails.
I've found that the problem is in the method used by imageData to
allocate the memory for the image byte array, if I use "malloc or new"
the error appears but if i user GlobalAlloc and GlobalLock the program
works fine.
I've verified that the memory is always allocated/deallocated correctly
and that the bytes always rappresent a correct bitmap.
Any idea about this behaviour ?
Thanks
Stefano
 
 

Re:CreateBitmap error

Hi,
I've a problem using the following code:
HBITMAP hBmp = CreateBitmap (
imageData.getWidth(), // bitmap width, in pixels
imageData.getHeight(), // bitmap height, in pixels
1, // number of color planes used by device
imageData.getFormat(), // number of bits required to identify
a
color
imageData.getBytes() // return a pointer to the array
containing color data
);
if (hBmp == NULL)
throw Exception("CreateBitmap error! code=" +
AnsiString(GetLastError()));
Picture->Bitmap->Handle = hBmp; //Show the bitmap
imageData is a custom object that handles the array of bytes and some
other information about the image.
After some executions of the code CreateBitmap fails.
I've found that the problem is in the method used by imageData to
allocate the memory for the image byte array, if I use "malloc or new"
the error appears but if i user GlobalAlloc and GlobalLock the program
works fine.
I've verified that the memory is always allocated/deallocated correctly
and that the bytes always rappresent a correct bitmap.
Any idea about this behaviour ?
Thanks
Stefano