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.
DenManAsked:
Who is Participating?
 
mahnoConnect With a Mentor Commented:
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)

mahno
0
 
jianliuerCommented:
The use of CBitmap::GetBitmapBits().
0
 
cdesignerCommented:
do you have CDib class?
this is best way
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
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)?
0
 
cdesignerCommented:
CDib class not from MFC, this class for work with *.BMP files, load in CBitmap object , access to RGB table ...

ftp://ftp.wegadesign.com/pub/wegabyte/cdib.zip
0
 
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;
      dcMem.CreateCompatibleDC(&dcScreen);

      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);

      dcMem.SelectObject(pOldBM);
      vBM.DeleteObject();

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!
0
 
cdesignerCommented:
hmmm
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 .
0
 
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.
0
All Courses

From novice to tech pro — start learning today.