How to display the Bitmap that created by CreateBitmap function?

  • Thread starter Thread starter Jimmy Lu
  • Start date Start date
J

Jimmy Lu

I use CBitmap::CreateBitmap create a CBitmap object, and sets the bit datas
by CBitmap::SetBitmapBits, but I can not display it on the screen(ie. use
CDC::BitBlt). Thanks in advance.

My codes like:
CBitmap bmp;
bmp.CreateBitmap(50,50,1,24,NULL); //24 bit colors
bmp.SetBitmapBits(bufLen, pBuf); //pBuf points to valid data
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
dcMem.SelectObject(&bmp);
pDC->BitBlt(0,0,50,50,&dcMem,0,0,SRCCOPY); // fault! can not display the
map.
 
Jimmy Lu said:
I use CBitmap::CreateBitmap create a CBitmap object, and sets the bit datas
by CBitmap::SetBitmapBits, but I can not display it on the screen(ie. use
CDC::BitBlt). Thanks in advance.

My codes like:
CBitmap bmp;
bmp.CreateBitmap(50,50,1,24,NULL); //24 bit colors
bmp.SetBitmapBits(bufLen, pBuf); //pBuf points to valid data
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
dcMem.SelectObject(&bmp);
pDC->BitBlt(0,0,50,50,&dcMem,0,0,SRCCOPY); // fault! can not display the
map.

I'm pretty GDI impaired, so take this with a grain of salt. What I suspect
is that there is some disparity in the 'nBitsPixel' parameter used in your
call to CreateBitmap and the actual bits per pixel of your 'pBuf' data. How
is this buffer filled?
 
Hi Jimmy,

You must use a compatible bitmap if you use SetBitmapBits
(CreateCompatibleBitmap). SetBitmapbits is deprecated anyway, you would be
better off working with DIB's if you want to manipulate pixels directly.

Cheers

Doug Forster
 
Back
Top