I'm trying to create a Bitmap in c# app layer, filling it on C++ layer with OpenCV, and displaying it back in c#.
This leads to visualization issues. I wrote a simplified code which demonstrates the problem.
Results
My code
C# app:
int width = 640, height = 480;
Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
CppWrapper.fillImage((byte*)bmpData.Scan0.ToPointer(), width, height, bmpData.Stride);
bitmap.Save("filledBitmap.bmp", ImageFormat.Bmp);
C# wrapper:
[DllImport("CppWrapperLib.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static unsafe extern void fillImage(byte* im, int width, int height, int stride);
C++ Layer:
void __stdcall fillImage(byte* im, int width, int height, int stride)
{
cv::Mat mat(cv::Size(width, height), CV_8UC1, im, stride);
mat.setTo(0);
cv::circle(mat, cv::Point(width / 2, height / 2), 50, 255,-1);
cv::circle(mat, cv::Point(width / 2, height / 2), 40, 180, -1);
cv::circle(mat, cv::Point(width / 2, height / 2), 30, 150, -1);
cv::circle(mat, cv::Point(width / 2, height / 2), 20, 120, -1);
cv::circle(mat, cv::Point(width / 2, height / 2), 10, 80, -1);
}
Thanks!

