title: C# LockBits perfomance (int[,] to byte[])
body: <pre><code>Graphics g;
  using (var bmp = new Bitmap(_frame, _height, PixelFormat.Format24bppRgb))
  {
      var data = bmp.LockBits(new Rectangle(0, 0, _frame, _height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
      var bmpWidth = data.Stride;
      var bytes = bmpWidth * _height;
      var rgb = new byte[bytes];
      var ptr = data.Scan0;
      Marshal.Copy(ptr, rgb, 0, bytes);
  
      for (var i = 0; i &lt; _frame; i++)
      {
          var i3 = (i &lt;&lt; 1) + i;
          for (var j = 0; j &lt; _height; j++)
          {
              var ij = j * bmpWidth + i3;
              var val = (byte)(_values[i, j]);
              rgb[ij] = val;
              rgb[ij + 1] = val;
              rgb[ij + 2] = val;
          }
      }
  
      Marshal.Copy(rgb, 0, ptr, bytes);
      bmp.UnlockBits(data);
  
      g = _box.CreateGraphics();
      g.InterpolationMode = InterpolationMode.NearestNeighbor;
      g.DrawImage(bmp, 0, 0, _box.Width, _box.Height);
  }
  g.Dispose();
  </code></pre>
  
  <p>I use this code to convert an array of RGB values ​​(grayscale) in the PictureBox, but it's slow. Please tell me my mistakes.
  At the moment, an array of 441 000 items handled for 35 ms.
  I need to handle an array of 4 million for the same time.</p>