Home All Groups Group Topic Archive Search About

Accessing Bitmap Bits

Author
30 Mar 2006 11:54 AM
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.

Author
30 Mar 2006 12:06 PM
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.

Show quote
"bern11" <ber***@yahoo.com> wrote in message
news:lJKdnYAPK5iNWrbZnZ2dnUVZ_sednZ2d@comcast.com...
>
> 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.
Author
30 Mar 2006 10:11 PM
bern11
Cool.....!

Kevin Spencer wrote:

Show quote
> See the Bitmap.LockBits method.
>

AddThis Social Bookmark Button