OpenCV 筆記 5.1 OPENCV的Array 使用Bitmap在C#的 pictureBox (指標方式 BitmapData )

背景知識

OpenCV 筆記 5 OPENCV的Array 使用Bitmap在C#的 pictureBox (簡單用 For 迴圈)

簡單來講 就是用了 BitmapData 再用 Marshal.Copy 把byte[]印過去

if (Camera1_Setting.Camera_Video_Capture(ref Camera1_Buffer, Camera_len_Buffer))
{
    
    int Width = 640;
    int Height = 480;
    Bitmap image0_Source = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);

    Rectangle rect = new Rectangle(0, 0, image0_Source.Width, image0_Source.Height);
    
    
    System.Drawing.Imaging.BitmapData bmpData = image0_Source.LockBits(
        rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,image0_Source.PixelFormat);
    System.Runtime.InteropServices.Marshal.Copy(Camera1_Buffer, 0, bmpData.Scan0, bmpData.Stride * image0_Source.Height);
    image0_Source.UnlockBits(bmpData);


    pictureBox_Camera1.Image = image0_Source;


}

LockBitsUnlockBits 是一對的記得要連在一起用