---
title: "Find image format using Bitmap object in C#"  
description: "Find image format using Bitmap object in C#"  
author: "Samuel Fernandes"  
published: 2014-01-30  
updated: 2014-01-30  
canonical: https://www.mindstick.com/forum/1924/find-image-format-using-bitmap-object-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Find image format using Bitmap object in C#

I am loading the [binary](https://www.mindstick.com/forum/34709/please-write-a-program-for-decimal-to-binary-conversion-in-c-sharp) bytes of the [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) [hard drive](https://answers.mindstick.com/qa/49844/how-to-transfer-files-from-mac-powerbook-to-external-hard-drive) and loading it into a [Bitmap](https://www.mindstick.com/forum/1802/bitmap-images-binding) object. How do i find the image type[JPEG, PNG, BMP etc] from the Bitmap object?

Looks trivial. But, couldn't [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) it out!

**[Sample](https://www.mindstick.com/news/2174/mars-mission-by-nasa-prepares-for-tests) [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) to achieve this.**

```
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;    }}
```

## Replies

### Reply by Pravesh Singh

Hi Samuel,\

If you want to know the format of an image, you can load the file with the Image class, and check its RawFormat property:

```
using(Image img =Image.FromFile(@"C:\path\to\img.jpg")){    if(img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))    {      // ...    }}
```


---

Original Source: https://www.mindstick.com/forum/1924/find-image-format-using-bitmap-object-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
