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

背景知識

OpenCV 筆記 1 安裝配置 與 Camera測試

C# 的隨手筆記 1 - DLL的 C Array to C# Array (PInvoke)

範例為 cols 640 x row 480 

OpenCV 的 char* 的顏色順序是  (B,G,R)

 if (Camera_Setting.Camera_Video_Capture(ref Camera_Buffer, Camera_len_Buffer))
 {

     int Height = 480;
     int Width = 640;
     pictureBox_Camera1.Height = Height;
     pictureBox_Camera1.Width = Width;

     Bitmap image1 = new Bitmap(Width, Height);
     for (int y = 0; y < Height; y++)
     {
         for (int x = 0; x < Width; x++)
         {
             byte R_color = Camera_Buffer[(x * 3 + 2) + y * Width * 3];
             byte G_color = Camera_Buffer[(x * 3 + 1) + y * Width * 3];
             byte B_color = Camera_Buffer[(x * 3 + 0) + y * Width * 3];
             Color newColor = Color.FromArgb(R_color, G_color, B_color);
             image1.SetPixel(x, y, newColor);
         }
     }
     pictureBox_Camera1.Image = image1;
 }