Showing posts with label Format. Show all posts
Showing posts with label Format. Show all posts

Tuesday, December 08, 2009

Finding the Image Format

Here is a small code that I wrote to find the image format of an image.

This code will check for the raw image format of the image you select and will display in a pop up window.

Hope this helps.





  1. using System.Drawing.Imaging;








  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3.     openFileDialog1.ShowDialog();
  4.     Image img = Image.FromFile(openFileDialog1.FileName);
  5.     ImageFormat imgfmt = img.RawFormat;
  6.     if (imgfmt.Equals(ImageFormat.Bmp))
  7.         MessageBox.Show(ImageFormat.Bmp.ToString());
  8.     else if (imgfmt.Equals(ImageFormat.Jpeg))
  9.         MessageBox.Show(ImageFormat.Jpeg.ToString());
  10.     else if (imgfmt.Equals(ImageFormat.Tiff))
  11.         MessageBox.Show(ImageFormat.Tiff.ToString());
  12.     else if (imgfmt.Equals(ImageFormat.Wmf))
  13.         MessageBox.Show(ImageFormat.Wmf.ToString());
  14.     else if (imgfmt.Equals(ImageFormat.Icon))
  15.         MessageBox.Show(ImageFormat.Icon.ToString());
  16.     else if (imgfmt.Equals(ImageFormat.Png))
  17.         MessageBox.Show(ImageFormat.Png.ToString());
  18.     else if (imgfmt.Equals(ImageFormat.Gif))
  19.         MessageBox.Show(ImageFormat.Gif.ToString());
  20. }