Mime Type From Image Format - CSharp System.Drawing.Imaging

CSharp examples for System.Drawing.Imaging:ImageFormat

Description

Mime Type From Image Format

Demo Code


using System.Net;
using System.IO;/*  w w  w  .  j  a va 2 s . co m*/
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing;
using System;

public class Main{
        public static String MimeTypeFromImageFormat(ImageFormat format) {
         if (format.Equals(ImageFormat.Jpeg)) {
            return MIME_JPEG;
         } else if (format.Equals(ImageFormat.Gif)) {
            return MIME_GIF;
         } else if (format.Equals(ImageFormat.Bmp)) {
            return MIME_BMP;
         } else if (format.Equals(ImageFormat.Tiff)) {
            return MIME_TIFF;
         } else if (format.Equals(ImageFormat.Png)) {
            return MIME_PNG;
         } else {
            throw new ArgumentException("Unsupported  image format '" + format + "'", "format");
         }
      }
}

Related Tutorials