C# .NET - image format - Asked By Lavinia Rayan on 01-Oct-10 04:17 AM

Hi,

How will view the .tif format image in web application through image control?
Sagar P replied to Lavinia Rayan on 01-Oct-10 04:33 AM
TIFF images are not supported in IE and cannot be displayed in both server and HTML image controls. Therefore we need to convert it into a IE supported image type such as GIF, JPEG, PNG, or BMP format. Internet Explorer displays images with the following extensions .art, .wmf, .emf, .png, .mov, .xbm, .avi, .mpg, .gif, .jpg, .mpeg, and .bmp.

We will convert the TIFF image to GIF format before displaying in a web page.

To convert TIFF image into GIF format, we need to use a dummy .aspx page which will convert the TIFF image to GIF format and then write it as
an output stream to the Response object.

The Response.OutputStream property enables binary output to the outgoing HTTP content body. To convert the TIFF to GIF format and write it into Http
output stream, do the following steps:

1. Create an .aspx page and name it as ShowImage.aspx.
2. Do not add any control to that page.
3. Add the following namespace in that page System.Drawing and System.Drawing.Imaging;
4. In Page_Load event write the following code

protected void Page_Load(object sender, EventArgs e)
{
    Response.ContentType = "image/gif";
    string fileName = HttpRuntime.AppDomainAppPath + @"\" +       Request.QueryString["ImageFileName"];
    new Bitmap(fileName).Save(Response.OutputStream, ImageFormat.Gif);
}

Here the Response.ContentType is used to set the HTTP MIME type of the output stream.
The instance of Bitmap object is used to save the TIFF image to GIF format into output stream.


Display the content of TIFF file in a image control

Assume that you want to display the image file testimage.TIFF in a HTML image control in another web page, for example in DemoPage.aspx.

1. Add an <img> control to DemoPage.aspx
2. In the src attribute, instead of giving a file name, just use the ShowImage.aspx and pass the TIFF file name as query string as below:

<img src="ShowImage.aspx?ImageFileName=testimage.TIF" />

3. This will render the testimage.TIFF image as GIF at run time and display it in the <img> control.
4. Your DemoPage.aspx will be like


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoPage1.aspx.cs" Inherits="DemoPage1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>TIFF Image Demo By Ramesh.S</title>

</head>
<body>
<form id="form1" runat="server">
<div>
   <table width="100%">
<tr>
<td class="style1">
Display TIFF Image
</td>
<td>
<img src="ShowImage.aspx?ImageFileName=testimage.TIFF" />
</td>
   </tr>
</table>
</div>
    </form>
</body>
</html>
Santhosh N replied to Lavinia Rayan on 01-Oct-10 04:50 AM
The better way to do this is to convert the tiff image to bmp or gif and then display as tif are not supported by default in the browsers..
check here for more info on how to accomplish this..
http://forums.asp.net/p/1541310/3804255.aspx
http://www.dotnetspider.com/resources/30795-Display-TIFF-Images-ASP-NET.aspx
DL M replied to Lavinia Rayan on 01-Oct-10 06:22 AM
show .tif file alter net way here in vb.net and C# code http://www.neodynamic.com/ND/FaqsTipsTricks.aspx?tabid=66&prodid=4&sid=4
mv ark replied to Lavinia Rayan on 01-Oct-10 06:37 AM
You can use http://docs.google.com/viewer & its embedded mode interface to display the tiff within your web page