Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CreateBitmap problem

2 views
Skip to first unread message

Silla Rizzoli

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to
Hi all,
I have a question about the behaviour of the CreateBitmap function:

HBITMAP CreateBitmap(
int nWidth, // bitmap width, in pixels
int nHeight, // bitmap height, in pixels
UINT cPlanes, // number of color planes used by device
UINT cBitsPerPel, // number of bits required to identify a color
CONST VOID *lpvBits // pointer to array containing color data
);

As you can see, the last parameter of this function is a pointer to the
actual bitmap data; does this function allocates new space in memory and
then copies the array pointed by lpvBits to the newly allocated memory or
simply uses the bitmap data already available?

Thanks in advance,
Silla Rizzoli

Chris Becke

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to


Don't use CreateBitmap, use CreateDIBitmap or CreateCompatibleBitmap.
CreateDIBitmap & CreateCompatibleBitmap both will create a bitmap that is
guaranteed to be compatible (ie can be blitted to) with the screen. In
addition, CreateDIBitmap takes a pointer to a device independent bitmap (ie
the data contained within a .bmp file).

CreateBitmap on the other hand will create the bitmap you specify, but if
the cPlanes and cBitsPerPel settings do not match the current display
settings the bitmap can not be blitted to the display. lpvBits also refers
to data formatted as per the device settings (ie data retrieved by calling
GetBitmapBits).

In all cases (CreateDIBitmap, and CreateBitmap) the data you pass in can be
destroyed when the Create function returns. The display driver allocates
memory internally for the bitmap, and copies the data you specify into the
internal structure.

If you are looking to access a bitmaps internal memory area, then take a
look at the CreateDIBSection API. A DIBSection gives you access to a memory
area that is formatted like a device independent bitmap. Changing bytes here
directly affects the result of blitting with the HBITMAP it also returns.
DIBSections can always be blitted to the display.

Chris [MVP]
--


Feng Yuan

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to
It allocates space in system area, which is the 32-bit GDI heap in Win95, or
kernel paged-pool in WinNT.

Feng Y

0 new messages