title: How to display raw data as an image (Visual Studio c#)
body: <p>I will be receiving some raw data that will be stored in a byte array, where each 2 bytes is a pixel value (16 bits/px). To start with, the array will contain 100x100*2 bytes (enough for a 100x100 pixel image). I would like to display this data in the Form window. Eventually, I would like to refresh the image with the new data to make it look like a video stream. No strict frame rate is required. How can this be done? Any code examples in C#? </p>
  
  <p><strong>EDIT:</strong>
  After some suggestions and reviews of tens of similar questions I still can not get this going. Here's the general idea of what I am trying to do, but the image is not displayed in the picture box on the form. <strong>What is specifically wrong with my implementation and how to fix it</strong>?</p>
  
  <pre><code>// array of data I collected
  byte[] dataArray = new byte[100 * 100 * 2]; 
  //create a pointer to the data
  IntPtr hglobal = Marshal.AllocHGlobal(100 * 100 * 2);
  
  // copy my array to global
  Marshal.Copy(dataArray, 0, hglobal, dataArray.Length);
  // create a bitmap: 100x100 pixels, 2bytes/pixel, 16bitgrayscale
  Bitmap newBitmap = new Bitmap(100, 100, 2 * 100, PixelFormat.Format16bppGrayScale, hglobal);
  
  // display bitmap
  pictureBox1.Image = newBitmap;
  
  // free the memory
  Marshal.FreeHGlobal(hglobal);
  </code></pre>