Imaging

Get the MIME type of a System.Drawing Image

I needed a method to get the mime type of a System.Drawing Image instance that I'd loaded from an upload. All articles I was able to find online suggest some kind of lookup table solution. There's actually another way. Given an Image i, you can map from the i.RawFormat.Guid property to an ImageCodecInfo.FormatID. So it becomes a very simple for loop to get the MIME type of an image or bitmap. This works for any format System.Drawing/GDI+ supports (bmp, png, tiff, jpg/jpeg, etc). Here's the code: public static string GetMimeType(Image i) {     foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageDecoders())     {         if (codec.FormatID == i.RawFormat.Guid)             return codec.MimeType;     }     return "image/unknown"; } This won't work for...

posted @ Thursday, January 17, 2008 12:10 PM | Feedback (7)

Save as G4 CCITT TIFF with .NET

My friend Rob Garrett recently started a Design Patterns post series on his blog. This seems like a great way to share experience with the community and stimulate thought and discussion. I decided to start a series on imaging with .NET, to share some of my experiences and the techniques that enable advanced solutions with .NET imaging and GDI+. This is the kickoff post for the series. In my experience, simple things in .NET are well documented, but it can be hard to find information on how to do complex things. One thing that took me awhile to figure out is...

posted @ Sunday, June 10, 2007 9:19 PM | Feedback (0)