title: Find image format using Bitmap object in C#
body: <p>I am loading the binary bytes of the image file hard drive and loading it into a Bitmap object. How do i find the image type[JPEG, PNG, BMP etc] from the Bitmap object?</p>
  
  <p>Looks trivial. But, couldn't figure it out!</p>
  
  <p>Is there an alternative approach?</p>
  
  <p>Appreciate your response.</p>
  
  <p><strong>UPDATED CORRECT SOLUTION:</strong> </p>
  
  <p>@CMS: Thanks for the correct response!</p>
  
  <p>Sample code to achieve this.</p>
  
  <pre><code>using (MemoryStream imageMemStream = new MemoryStream(fileData))
  {
      using (Bitmap bitmap = new Bitmap(imageMemStream))
      {
          ImageFormat imageFormat = bitmap.RawFormat;
          if (bitmap.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
              //It's a JPEG;
          else if (bitmap.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
              //It's a PNG;
      }
  }
  </code></pre>