Annyms

Hello all,

I'm having trouble converting an unsigned char* into a Bitmap image. I have an unsigned char* in managed c++ code, which points to a 1280x1024 image with 8bppIndexed as the pixel format. When I display the image using the raw unsigned char* I'm getting the right image.

In order to display the image on a C# console window, I need to convert the image from my C++ code in a System:Big Smilerawing::Bitmap object. To do this, I have attempted to cast the pointer to IntPtr:

IntPtr a_image_data = (IntPtr)const_cast<unsigned char*>( image_data ); //image_data is the unsigned char*

I then used a delegate and event pair to send this IntPtr to the C# side of my project, and it retains the same IntPtr value. When I recreate the image using the IntPtr, it gives me an unrelated image.

System.Drawing.Bitmap RetrievedImage= new System.Drawing.Bitmap(1280, 1024, 8,

System.Drawing.Imaging.PixelFormat.Format8bppIndexed, ImageData); //ImageData is the IntPtr

boxPic.Image = RetrievedImage; //Display the image in PictureBox

I think there is a problem in the casting. Please advise. Thank you.



Re: Visual C# General Converting from unsigned char* to Bitmap

Peter Ritchie

What data does image_data point to Did you load it from file, is it a screen capture, raw bits, etc




Re: Visual C# General Converting from unsigned char* to Bitmap

Annyms

It's passed back directly from hardware written for the camera, so I think it's raw bits.



Re: Visual C# General Converting from unsigned char* to Bitmap

Peter Ritchie

It's hard to say what you need to do unless we know what format the raw data is in. It could be interleaved, packed, jpeg, indexed, etc.

Are you communicating directly with the camera