C# call a c++ method, which is called GetSourceImage(…)The following is the way how we get the bitmap data by copying srcBmpData to dstBmpdata, and showing them on a pictureBox.The copy sequence is just the same as OpenCV BGR, it looks as though we create a Format32bppArgb image. ,
1: this.Invoke((MethodInvoker)delegate
2: { 3: int width, height, channel, step;
4: unsafe
5: { 6: byte* srcBmpData = cVideo.GetSourceImage(&width, &height, &channel, &step);
7: Result_lbl.Text = $"{width},{height},{channel},{step}"; 8: Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
9: var data = bmp.LockBits(new Rectangle(0, 0, width, height),
10: System.Drawing.Imaging.ImageLockMode.WriteOnly,
11: System.Drawing.Imaging.PixelFormat.Format32bppRgb);
12: byte* dstBmpData = (byte*)data.Scan0.ToPointer();
13: int hei = height;
14: int wid = width;
15: int stepsize = step;
16:
17:
18: for (int y = 0; y < height; y++)
19: { 20: for (int x = 0; x < width; x++)
21: { 22: dstBmpData[y * width * 4 + 4 * x] = srcBmpData[y * step + channel * x];
23: dstBmpData[y * width * 4 + 4 * x + 1] = srcBmpData[y * step + channel * x + 1];
24: dstBmpData[y * width * 4 + 4 * x + 2] = srcBmpData[y * step + channel * x + 2];
25: }
26: }
27: bmp.UnlockBits(data);
28: pictureBox1.Image = bmp;
29: }
30: });