Archived

This topic is now archived and is closed to further replies.

Sailorstick

Why are the bits STILL null?

Recommended Posts

I''m trying to access the bits of bitmap directly because GetBitmapBits is too slow and only copies the bits, which requires you to use SetBitmapBits again when you have finished with them. Here''s the code I''m using, but no matter what I do, the bits are always 0x00000000. All other BITMAP values are correct however
this->FrontBuffer = GetDC(this->hWnd); //main window (already created)

this->BackBuffer = CreateCompatibleDC(this->FrontBuffer);
SetBkMode(this->BackBuffer, TRANSPARENT);
this->backBmp = CreateCompatibleBitmap(this->FrontBuffer, this->width, this->height); //bitmap is created.  Should have width*3*height BYTES

SelectObject(this->BackBuffer, this->backBmp);
...
//access the bits of the BackBuffer and modify

GetObject(this->backBmp, sizeof(BITMAP), &bmp);
scanw=bmp.bmWidthBytes;
bits=(BYTE*)bmp.bmBits; <----- Here they are always NULL.

Share this post


Link to post
Share on other sites
Checked the result of GetObject, or the value of scanw?

MSDN sayeth:


Object type Data written to buffer
HBITMAP BITMAP

HBITMAP returned
from a call to
CreateDIBSection DIBSECTION, if cbBuffer is set to sizeof
(DIBSECTION), or BITMAP, if cbBuffer is
set to sizeof(BITMAP)


"If hgdiobj is a handle to a bitmap created by calling CreateDIBSection, and the specified buffer is large enough, the GetObject function returns a DIBSECTION structure. In addition, the bmBits member of the BITMAP structure contained within the DIBSECTION will contain a pointer to the bitmap's bit values.

If hgdiobj is a handle to a bitmap created by any other means, GetObject returns only the width, height, and color format information of the bitmap. You can obtain the bitmap's bit values by calling the GetDIBits or GetBitmapBits function."

Looking at the first table, you seem to be using the 2nd method, and therefore it's implying that it doesn't make bmBits available to you except through GetDIBits or GetBitmapBits.


[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]


[edited by - Kylotan on July 2, 2003 9:53:19 AM]

[edited by - Kylotan on July 2, 2003 9:53:38 AM]

Share this post


Link to post
Share on other sites