Getting image as unsigned char array

A

arwen_h

Hi everyone,
I'm developing a form with .Net, in C++. I have to display a choosen
image on a pic-box and then I have to do some elaborations on it.
I need to get the Image (which I open from a dialog) as an unsigned char
array, some sort of:
image --> unsigned char buffer[]
because I have a whole of algorithms to use that use image-array like that.

I have already displayed the image and converted to Image class, but I dont
know
how to convert it into uchar array.

Thank you and forgive my poor english!
 
T

Tom Widmer

arwen_h said:
Hi everyone,
I'm developing a form with .Net, in C++. I have to display a choosen
image on a pic-box and then I have to do some elaborations on it.
I need to get the Image (which I open from a dialog) as an unsigned char
array, some sort of:
image --> unsigned char buffer[]
because I have a whole of algorithms to use that use image-array like that.

I have already displayed the image and converted to Image class, but I dont
know
how to convert it into uchar array.

Thank you and forgive my poor english!

Bitmap::LockBits seems to be what you want:
http://msdn.microsoft.com/library/d...lasses/bitmapclass/bitmapmethods/lockbits.asp

Note that you'll need to make sure that the format of the unsigned chars
is correct. And you need a Bitmap rather than an Image (though Bitmap is
a subclass of Image).

Tom
 
S

Sebastian Dau

Try this lines, that should work for C++.NET Image conversion...

System::Drawing::ImageConverter __gc* ic = new
System::Drawing::ImageConverter();

byte[] photo = new byte[1];

try
{
photo = try_cast<byte[]>( ic->ConvertTo(imagen, photo.GetType());
}
catch ( Exception __gc* ex )
{
Debug::WriteLine(er->ToString() );
}


Bye Sebastian Dau
 

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