Getting bitmap bits

I am trying to write text to a bitmap, then get access to the image buffer to do some pixel-level manipulations. I have been unable to get the buffer to fill using either the CBitmap::GetBitmap() or GetDIBits() functions - in both cases, the buffer remains null or empty. Does anyone have an example of functional code that does this, or have suggestions how to make it work? Thanks.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The use of CBitmap::GetBitmapBits().
do you have CDib class?
this is best way
DenManAuthor Commented:
Is CDib available in MFC 4.2 (I'm using VC++ 5.0)?

Also...I have tried GetBitmapBits, and the buffer it returns does not have an obvious correlation with what the contents should be. Is the standard buffer returned from GetBitmapBits in lookup-table format, or RGB format (i.e. 8-bit or 24-bit)?
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

CDib class not from MFC, this class for work with *.BMP files, load in CBitmap object , access to RGB table ...
DenManAuthor Commented:
Thanks, I'll look into it.  I'm actually trying to create a small bitmap (with text in the image) that I can paste onto an existing image that is in raw data format. (I need the raw data to pass into image compression schemes I did not write).

Here is an example of code which seems like it should work, but no data is ever returned.

      CBitmap vBM;
      CClientDC dcScreen(this);
      CDC dcMem;

      vBM.CreateBitmap(20, 10, 1, 24, NULL);
      CBitmap *pOldBM = (CBitmap *) dcMem.SelectObject(&vBM);

      CBrush graybrush(RGB(128,128,128));
      CBrush whitebrush(RGB(255,255,255));

      dcMem.FillRect(CRect(0, 0, 20, 10), &graybrush);
      dcMem.FillRect(CRect(0, 0, 2, 4), &whitebrush);

      BITMAP vBMInfo;
      int vCount;
      char *pBuffer;
      vBM.GetObject(vCount, &vBMInfo); // here, count always returns as 0
      pBuffer = new char[vCount];
      vBM.GetBitmapBits(vCount, pBuffer);


I have also tried with using a pre-created char * array instead of NULL in the CreateBitmap, but when I do that the GetObject does not even return info to the BITMAP structure!
I have a game ...
In game I need a paint backround and some squares. With CDib Im load background and modufy this directly. This is simply way, and fast. Try .
DenManAuthor Commented:
I don't want to have to keep a bitmap on disk in order to be able to load it - I want to create it in memory. My fundamental goal is to place a block of text onto an existing image that is not in DIB or DDB format, so I was hoping to create a small bitmap, write the text onto the bitmap, extract the bits of the bitmap and copy them onto the existing image. If there is an easier way to do it, I'd love to hear it -- if I can't figure this out I'm going to have to create my own font and manually place characters onto the image, a task I don't relish.
Hi DenMan,

If U still interesting to get the answer, I can tell U about method GetBitmapBits()

>Also...I have tried GetBitmapBits, and >the buffer it returns does not have an >obvious correlation with what the >contents should be. Is the standard >buffer returned from GetBitmapBits in >lookup-table format, or RGB format
>(i.e. 8-bit or 24-bit)?

U receive buffer, where:
each pixel is represented by word:

0rrr rrgg gggb bbbb

r - red
g - green
b - blue

(5bit to each color component)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.