Accessing Bitmap Bits

B

bern11

What is the best way to access the bits in a bitmap loaded into an
image control (I'm converting a color image to greyscale). I have a
method which works, but it seems kindof cludgy. Here is what I did:

HBITMAP hSrcBmp; // GDI Bitmap Handle
BITMAP SrcBmp; // GDI Bitmap
int iStatus, iDims[2];
char *cSrc; // Pointer to Bits

// MyImagePbx is a picturebox control with an bitmap already loaded
// EditSrcBmp is a global Bitmap^
EditSrcBmp = gcnew Bitmap(MyImagePbx->Image);

// Create? a GDI bitmap
hSrcBmp = (HBITMAP)EditSrcBmp->GetHbitmap().ToInt32();

// Get bitmap object
iStatus = GetObject(hSrcBmp,sizeof(SrcBmp),&SrcBmp);

// Now i have direct access
cSrc = (char *)SrcBmp.bmBits;


// Do I have to release or destroy the hSrcBmp bitmap handle?


It seems like there has to be a better way.
 
K

Kevin Spencer

See the Bitmap.LockBits method.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top