Hoping someone here on the forum's can put me right on the above matter, after reading some I thought I could achieve the task in the following steps...

[Visual C++]

[1] Convert AxisMediaControl image to system object
[2] Convert object to ByteArray
[3] Convert ByteArray to CharArray
[4] Assign CharArray to struct


[Native c++ DLL]

[1]CharArray from struct to IplImage* img

[Visual C++]

// Define struct to hold image data
struct AnalysisData
{
	
	unsigned char* ImgData;

};

AnalysisData ImageData;

// Get current image of axAxisMediaControl1
int theFormat = 0;// 0=jpeg 1=BMP
Object^ theImgBuffer = gcnew Object();
__int32 theBufferSize;
this->axAxisMediaControl1->GetCurrentImage(theFormat, theImgBuffer, theBufferSize);

//Convert Image object to byte array
array<System::Byte> ^_ByteArray = ObjectToByteArray(theImgBuffer);

//Convert Byte Array to Char Array
for(int i = 0; i < _ByteArray->Length; i++)
{
	ImageData.ImgData[i] = (unsigned char)_ByteArray[i];
						
	//ImageData.ImgData[i] = static_cast<unsigned char>(_ByteArray[i]);
						
	/*pin_ptr<System::Byte> p = &_ByteArray[i];
	unsigned char* pby = p;
	ImageData.ImgData[i] = reinterpret_cast<unsigned char>(pby);*/
	
	/*
	[NOTE]
	Tried all the above but seems to hang here ??
	*/
}
/*
Program continues & call native DLL...
*/

/************************************************

Convert object into byte array
		
************************************************/
array<System::Byte> ^ObjectToByteArray(System::Object ^_Object)
{
	try
	{
	// create new memory stream
	System::IO::MemoryStream ^_MemoryStream = gcnew System::IO::MemoryStream();
	// create new BinaryFormatter
	System::Runtime::Serialization::Formatters::Binary::BinaryFormatter^_BinaryFormatter = gcnew  System::Runtime::Serialization::Formatters::Binary::BinaryFormatter();
	// Serializes an object, or graph of connected objects, to the given stream.
	_BinaryFormatter->Serialize(_MemoryStream, _Object);
	// convert stream to byte array and return
	return _MemoryStream->ToArray();
	}
	catch (...)
	{
	// Error
	//Console::WriteLine("Exception caught in process: {0}", _Exception->ToString());
	}

	// Error occured, return null
	return nullptr;
	}
[Native C++ DLL]


IplImage* img;

// Called DLL Function
AnalysisData DLL_EXPORT ImageProcess(struct AnalysisData *ImageData)
{
	     //Create IplImage* from struct data
            CvSize size = cvSize(640,480);
            img = cvCreateImageHeader(size, 8,3);
            img->imageData = ImageData->ImgData;

            //Continued...
}

The problem seems to be here as it hangs, but that said wondering if the process is the right way to achieve the task ? or is it a bit long winded, any help would be appreciated many thanks.

//Convert Byte Array to Char Array
for(int i = 0; i < _ByteArray->Length; i++)
{
	ImageData.ImgData[i] = (unsigned char)_ByteArray[i];
 
	//ImageData.ImgData[i] = static_cast<unsigned char>(_ByteArray[i]);
 
	/*pin_ptr<System::Byte> p = &_ByteArray[i];
	unsigned char* pby = p;
	ImageData.ImgData[i] = reinterpret_cast<unsigned char>(pby);*/
 
	/*
	[NOTE]
	Tried all the above but seems to hang here ??
	*/
}

[Update]

// Get current image of axAxisMediaControl1
int theFormat = 0;
Object^ theImgBuffer = gcnew Object();
__int32 theBufferSize;
this->axAxisMediaControl1->GetCurrentImage(theFormat, theImgBuffer, theBufferSize);

It looks like the "theImgBuffer" is already a charArray, so my question is if this being the case
how do you access the index values of the "theImgBuffer"

tried this...

for(int i = 0; i < theBufferSize; i++)
{
	ImageData.ImgData[i] = (unsigned char)theImgBuffer[i];
						
}

but get error

'System::Object' has no default indexed property

Many Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.