Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am using ashx handler to display multitiff image

it shows me first page how can retrive image using button click I have 25 pages in the tiff image

my ashx is
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;


namespace WebApplication1
{
    /// <summary>
    /// Summary description for Handler1
    /// </summary>
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string path = context.Server.MapPath("~/image/045237302.tif");
        Image img = Image.FromFile(path);
       img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
       context.Response.ContentType = "image/tif";
        


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

my aspx page is
ASP
<%@ Page Language="C#" %>


<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
   <script runat="server">


    protected void Button1_Click(object sender, EventArgs e)


    {
        //if (PathDirection =!null)
        //int stratpg = 1;
        //if (Request.QueryString["startpg"] !=null)
        Image img = new Image();
        img.ImageUrl = "Handler1.ashx";
        Page.Form.Controls.Add(img);
    }


</script> 

</head>
<body>
    <form id="form1" runat="server">
    <div>
       

        <asp:Button ID="Button1" runat="server" Text="Display Tiff file"  OnClick="Button1_Click"/>
        <asp:Image ID="Image1" ImageUrl="~/Handler1.ashx" runat="server" />
    </div>
    </form>
</body>
</html>

can anybody help me.

I need help reading page by page



Thanks

Mary
Posted
Updated 24-Jan-14 17:10pm
v4
Comments
Ahmed Bensaid 24-Jan-14 11:51am    
Your question is not really clear ... Can you accurately explain your problem ?
Mary Abraham 24-Jan-14 12:38pm    
My problem is I have a tiff image which has multipage
when I try to load it is only showing the first page how to get the page count of the file and display one by one.
Mary Abraham 24-Jan-14 15:39pm    
Hi I go the page count working but I dont know how to retrive page by page by clicking the button

my ashx page is

namespace WebApplication1
{
///
/// Summary description for Handler1
///

public class Handler1 : IHttpHandler
{


public void ProcessRequest(HttpContext context)
{
string path = context.Server.MapPath("~/image/045237302.tif");
Image img = Image.FromFile(path);



int count = img.GetFrameCount(FrameDimension.Page);
for (int idx = 0; idx < count; idx++);
MemoryStream byteStream = new MemoryStream();

//images.Add(Image.FromStream(byteStream));


img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ContentType = "image/tif";

}

public bool IsReusable
{
get
{
return false;
}
}
}
}

My Default aspx page is

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script runat="server">


protected void Button1_Click(object sender, EventArgs e)


{
//if (!IsPostBack){
Image img = new Image();
img.ImageUrl = "Handler1.ashx";
Page.Form.Controls.Add(img);
}


</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Display Tiff file" OnClick="Button1_Click"/>
<asp:Image ID="Image1" width="443px" Height ="380px" ImageUrl="~/Handler1.ashx"
runat="server" Visible="False" />
</div>
<asp:Button ID="Button2" runat="server" Text="Display next page" OnClick="Button1_Click" />
</form>
</body>
</html>

I dont know how to retrive pages by clicking the button it is only loading the first page but I got the count working.

1 solution

1. You are saving the TIF file as a JPG format on the OutputStream but you set the ContentType to image/tif!!! Make both match!

2. Here is how to get a given "page/frame" inside your tif file http://www.davidloo.com/?p=15[^]

NOTE: GDI+ (i.e. System.Drawing) does not support all tif compression methods so be sure that all your tif files work before relying on it.
 
Share this answer
 
Comments
Mary Abraham 27-Jan-14 10:45am    
Hi

can you help me in creating aspx page www.davidloo.com is windows application
I am able to create windows application but dont know how to create the same in aspx
because dont know what we can use instead of picture box control in asp.net

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900