I wrote this sample code to explain my problem. I have a solution in VS 2013, contains one C# project and a C++ project. I try to read an image with OpenCV in C++ (x86). and want to pass in to a C# x86 project (used CLR mode) to a Bitmap Object and Then BitmapImage Object to use as a WPF ImageSource.
My C++ Code:
Bitmap^ SomeClass::Test(System::String^ imgFileName)
{
auto fileName = msclr::interop::marshal_as(imgFileName);
Mat img = imread(fileName);
//Do something
auto bmp = gcnew Bitmap(img.cols, img.rows, img.step, Imaging::PixelFormat::Format24bppRgb, (IntPtr)img.data);
bmp->Save("InC++Side.png");
return bmp;
}
My C# Code:
private void ImageTester(object sender, RoutedEventArgs e)
{
var image = testClass.