title: Converting RAW byte data to Bitmap
body: <p>I am taking a screenshot of an android device using ADB and receiving the screenshot as raw byte data.</p>
  
  <p>I know the raw byte data coming through is in the format rgba</p>
  
  <p>Red is offset 0, Green offset 8, Blue offset 16, Alpha offset 24, each value is 1 byte. This makes up the entire byte array.</p>
  
  <p>I am trying to convert this byte array to a Bitmap in C# and it is working for the most part, the image looks correct in every way apart from the fact that it is coming through with a 'blue hue' -- the coloring is off.</p>
  
  <p>The following is the code I'm using to convert my raw byte data:</p>
  
  <pre><code>int WriteBitmapFile(string filename, int width, int height, byte[] imageData)
      {
          using (var stream = new MemoryStream(imageData))
          using (var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb))
          {
              BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0,
                                                              bmp.Width,
                                                              bmp.Height),
                                                ImageLockMode.WriteOnly,
                                                bmp.PixelFormat);
              IntPtr pNative = bmpData.Scan0;
  
              Marshal.Copy(imageData, 0, pNative, imageData.Length);
  
              bmp.UnlockBits(bmpData);
  
              bmp.Save(filename);
          }
  
          return 1;
      }
  </code></pre>
  
  <p>I've read in <a href="https://stackoverflow.com/questions/8104461/pixelformat-format32bppargb-seems-to-have-wrong-byte-order" title="this post">this post</a> that it could be to do with the byte order of the actual rgba values. As you can see in the code above, I tried casting my bmpData.Scan0 to int* and it is still coming through with a blue hue.</p>
  
  <p>I'm wracking my brain as to what I can do now to get this image to come through with the correct colors. I'm assuming it's reading red as blue and blue as red or vice versa.</p>
  
  <p>I thought I could manipulate the raw byte data so that it is in the correct byte order when converting it to a bitmap, however I'm not sure how I can go about doing that.</p>
  
  <p>Any suggestions?</p>