I needed to display TIF images that were stored in the database.  Unfortunately it is not as simple as just setting the MIME Type and writing out the binary. So I asked Google and the overwhelming response I saw was to convert the TIF into another image type and then write out the binary.  Here is my take on the solution:

Written in C# (the image is sent via a Generic Handler hence the “context.Response”):

using (MemoryStream stream = new MemoryStream(Content))
{
   System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
   img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
   context.Response.ContentType = "image/gif";
}
Advertisements