Hi
I assume you are talking about a multipage tiff. I ll give you an example of display the multi page image in the page with radio button of pages.
In this example i am having a multipage tiff test.tiff at the solution root folder. you may need to use the correct path instead
In the default aspx page have this...
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Image runat="server" ID="img1" />
<asp:RadioButtonList ID="rbtnDataMatch" runat="server" RepeatDirection="Horizontal" Style="font-size: 10pt;" AutoPostBack="true" OnSelectedIndexChanged="rbtnDataMatch_SelectedIndexChanged">
</asp:RadioButtonList>
</asp:Content>
in the code behind of default aspx have this.....
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MultiPageTifHandler tifHandler = new MultiPageTifHandler();
int page_count = tifHandler.GetPageCount(Server.MapPath("Test.tiff"));
for (int i = 1; i <= page_count; i++)
{
ListItem item = new ListItem(i.ToString(), i.ToString());
rbtnDataMatch.Items.Add(item);
}
img1.ImageUrl = "~/ImageViewer.aspx?img_file=Test.tiff&page=1";
rbtnDataMatch.Items[0].Selected = true;
}
}
protected void rbtnDataMatch_SelectedIndexChanged(object sender, EventArgs e)
{
int index = rbtnDataMatch.SelectedIndex;
img1.ImageUrl = "~/ImageViewer.aspx?img_file=Test.tiff&page="+(rbtnDataMatch.SelectedIndex+1);
}
Add a new aspx webform to your project and name it ImageViewer. In the imageviewer code behind (ImageViewer.aspx.cs)... have this code...
protected void Page_Load(object sender, EventArgs e)
{
string imgFilePath =Server.MapPath( Request.QueryString["img_file"]);
int selectedPage = Convert.ToInt32(Request.QueryString["page"]);
MultiPageTifHandler tifHandler = new MultiPageTifHandler();
System.Drawing.Image img=tifHandler.GetTiffImage(imgFilePath, selectedPage);
Response.ContentType = "image/jpeg";
img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
}
Now add a new class file to your project named MultiPageTifHandler and have this code inside.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
public class MultiPageTifHandler
{
private int page_count;
public int GetPageCount(string imgFileName)
{
int page_count = -1;
Image multiTiff = null;
try
{
multiTiff = Image.FromFile(imgFileName);
page_count = multiTiff.GetFrameCount(FrameDimension.Page);
return page_count;
}
catch (Exception ex)
{
throw ex;
}
finally
{
multiTiff.Dispose();
}
}
public Image GetTiffImage(string imgFileName, int selectedPage)
{
int page_count = GetPageCount(imgFileName);
if ((selectedPage < 1) | (selectedPage > page_count))
{
throw new InvalidOperationException("Out of Page Range.");
}
MemoryStream ms = null;
Image inputImg = null;
Image pageImage = null;
try
{
inputImg = Image.FromFile(imgFileName);
ms = new MemoryStream();
FrameDimension dimension = new FrameDimension(inputImg.FrameDimensionsList[0]);
inputImg.SelectActiveFrame(dimension, selectedPage - 1);
inputImg.Save(ms, ImageFormat.Tiff);
pageImage = Image.FromStream(ms);
}
catch (Exception ex)
{
throw ex;
}
finally
{
inputImg.Dispose();
}
return pageImage;
}
}
Run the website , you will find the first page of the image displaying and there will be radio buttons upto the number of pages in the image. Now select the radio buttons you can see the corresponding page in the image displays. Good luck