Hayri Uğur Koltuk
Hayri Uğur Koltuk

Reputation: 3020

What is pixel format of HBITMAP when i get bitmap info with GetBitmapBits?

I have HBITMAP hBitmap. I use GetBitmapBits(hbitmap, width * height, buffer);

what is the pixel format written in buffer?

Thanks.

Upvotes: 0

Views: 2780

Answers (2)

Soonts
Soonts

Reputation: 21956

Can be different, it depends on the bitmap. Here’s a code to find out:

BITMAP bmp;
if( 0 == GetObject( hbitmap, sizeof( BITMAP ), &bmp ) ) // handle error

From that BITMAP structure you can find out pixel format and other important things about memory layout. For example, here’s a formula for the required buffer size: bmp.bmWidthBytes * bmp.bmHeight

Upvotes: 3

noelicus
noelicus

Reputation: 15055

You want to use GetDIBits instead.

Check out what MSDN says about it: GetDIBits

Always ask MSDN (if using Visual Studio)

Upvotes: 3

Related Questions