I have been given a bunch of ".tif" image files that should be displayed on to my .aspx pages.
Although i can see these images in design time. The asp:Image fails to render the image(.tif) on the browser.
If i use a .jpg file instead of tiff image, it renders perfectly.
Any ideas why this is a limitation ?
Things i tried
To have a Handler file SampleHandler.ashx in my project which does the processing of the request
public void ProcessRequest(HttpContext context)
{
string path = context.Server.MapPath("~/img/image.tif");
Image img = Image.FromFile(path);
img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
And referring the Handler in my aspx code.
Ex:
<img src="SampleHandler.ashx"/>
This approach works !! But what if i have multiple ".tif" files to be loaded ?
Thanks
Configuration : ASP.NET 2.0
VSNET2008
asp:Image only renders an img tag to the HTML output. Check the generated source to verify it has the right path. If it does, try to browse directly to that path and see if you get the image.
(Assuming you do not see the image on a direct browse it either means your server is not configured to serve tiff files or that you have an incorrect path).
You need to configure your web server to return the correct MIME type.
the correct mime type for tiff files is image/tiff
You need to be running IIS Express, IIS 7 or higher, and add the following to your web.config
<system.webServer>
<staticContent>
<mimeMap fileExtension=".tiff" mimeType="image/tiff" />
<mimeMap fileExtension=".tif" mimeType="image/tiff" />
</staticContent>
</system.webServer>
If you're running the webdev server you're out of luck (it's ancient). Install IIS Express or run IIS instead.
The .TIF (TIFF) file format is not typically supported by browsers. You should only ever expect current or older browsers to support GIF, JPG and PNG for image files. Refer to W3C page on images.
The reason this seems to work in the development environment is that it simply uses the OS to decode the image which will have support for more image formats. But it is only an illusion, as it is not supported by browsers.