How do i open a .tif file in an ASP page.
I am using VS-2005.
Is there any specific control available for opening .tif files.
Coz i have tried using Image and ImageMap controls without any joy.

Hi IE wont support tif files to display. so u need to convert that tif into gif or any otherformat. The following is some sample code. Hope it helps u.

System.IO.Stream _stream = new System.IO.FileStream(@"img\Calendar2008.tif", System.IO.FileMode.Open);
        Bitmap _bmp = new Bitmap(_stream);
        Context.Response.ContentType = "image/gif";
        _bmp.Save(Context.Response.OutputStream, ImageFormat.Gif);
        _bmp.Dispose();
        _stream.Close();

Hi IE wont support tif files to display. so u need to convert that tif into gif or any otherformat. The following is some sample code. Hope it helps u.

System.IO.Stream _stream = new System.IO.FileStream(@"img\Calendar2008.tif", System.IO.FileMode.Open);
        Bitmap _bmp = new Bitmap(_stream);
        Context.Response.ContentType = "image/gif";
        _bmp.Save(Context.Response.OutputStream, ImageFormat.Gif);
        _bmp.Dispose();
        _stream.Close();

Hi,

After converting into say .bmp how do i place it in an image control.

System.IO.Stream strm = new System.IO.FileStream(@"images_random\\abc.tif", System.IO.FileMode.Open);
Bitmap bmp = new Bitmap(strm);

This is throwing an exception.

hey try the following...

using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Imaging;
using System.Collections.Specialized;
using System.Drawing;
//using Microsoft.Web;

public partial class dani : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.IO.Stream _stream = new System.IO.FileStream(@"c:\Calendar2008.tif", System.IO.FileMode.Open);
        Bitmap _bmp = new Bitmap(_stream);
        Context.Response.ContentType = "image/bmp";
        _bmp.Save(@"c:\hi.bmp", ImageFormat.bmp);
        _bmp.Dispose();
        _stream.Close(); 
        ImageButton1.ImageUrl=@"c:\hi.bmp";
    }
}

hey try the following...

using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Imaging;
using System.Collections.Specialized;
using System.Drawing;
//using Microsoft.Web;

public partial class dani : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.IO.Stream _stream = new System.IO.FileStream(@"c:\Calendar2008.tif", System.IO.FileMode.Open);
        Bitmap _bmp = new Bitmap(_stream);
        Context.Response.ContentType = "image/bmp";
        _bmp.Save(@"c:\hi.bmp", ImageFormat.bmp);
        _bmp.Dispose();
        _stream.Close(); 
        ImageButton1.ImageUrl=@"c:\hi.bmp";
    }
}

Hi,
It is throwing exception at the following line:
Context.Response.ContentType = "image/bmp";

its working with out any exceptions here.......... have u included all the namespaces that i mentioned??

its working with out any exceptions here.......... have u included all the namespaces that i mentioned??

Yes i have included them all................
Still it is throwing exception................:(

1. Create an dummy .aspx, for example TiffImage.aspx.
2. Write the following code in the Page_Load event of the TiffImage.aspx

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
public partial class TiffImage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "image/gif";
        String imageFileName = HttpRuntime.AppDomainAppPath + Request.QueryString["ImagePath"];
        new Bitmap(imageFileName).Save(Response.OutputStream, ImageFormat.Gif);
    }
}

3. Assume that you want to display test.tiff file in the DemoPage.aspx . Then your HTML part of your DemoPage.aspx

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

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        [B]<img src="TiffImage.aspx?ImagePath=test.TIF" />[/B]
    </div>
    </form>
</body>
</html>

Here the test.tif is passed as a query string to TiffImage.aspx file where the TIFF file save as GIF and rendered in DemoPage.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.