title: How to change 12-bits and 10-bits raw file to bitmap image using c#
body: <p>I have 10-bits and 12-bits rawbayer (.raw) file. And i want to convert it to Bitmap image but i am unable to change it. 8-bits or 16-bits raw file changed easily but 10-bits or 12-bits can't be changed.</p>
  
  <p>here is the code for 8-bits raw file to Bitmap.</p>
  
  <pre><code>private void DisplayImage08(string fileName) //Raw file name
      {
          // Open a binary reader to read in the pixel data. 
          // We cannot use the usual image loading mechanisms since this is raw 
          // image data.         
          try
          {
              BinaryReader br = new BinaryReader(File.Open(fileName, FileMode.Open));
              byte pixByte;
              int i;
              int iTotalSize = (int)br.BaseStream.Length;
  
              // Get the dimensions of the image from the user
              ID = new ImageDimensions(iTotalSize); 
              width = Convert.ToInt32(ID.txtwidth);
              height = Convert.ToInt32(ID.txtheight);
              //panel1.Width = width;
              //panel1.Height = height;
              pictureBox1.Width = width;
              pictureBox1.Height = height;
              pix08 = new byte[iTotalSize];
                  //pix08 = new byte[iTotalSize];
  
              for (i = 0; i &lt; iTotalSize; ++i)
              {
  
                  pixByte = (byte)(br.ReadByte());
                  pix08[i] = pixByte;
              }
                  br.Close();
                 int bitsPerPixel = 8;
                  stride = (width * bitsPerPixel + 7) / 8;
  
                  // Single step creation of the image
                  bmps = BitmapSource.Create(width, height, 96, 96, PixelFormats.Gray8, null,
                      pix08, stride);
                  //Bitmap bmp = new Bitmap();
  
                 // img.Source = bmps;
                  Bitmap bt = BitmapFromSource(bmps); //Change Bitmap source to Bitmap
                  pictureBox1.Image = bt; //Display on pictureBox
  
  
  
                  pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
  
          }
          catch (Exception e)
          {
  
          }
      }
  </code></pre>
  
  <p>But i want to change 12-bits or 10 bits raw file to Bitmap.</p>
  
  <p>So please help me on this, that how can i change it?</p>
  
  <p>Thanks</p>