Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have set the page numbers to an embed image. If I select page "2"(2nd image) and click radio button, the page "1"(1st image) is being displayed automatically.. But I want the same selected image to remain on the page whenever I click on the radio button associted with it..

Please anyone suggest me..
Posted
Updated 25-Feb-11 21:55pm
v2
Comments
Ankur\m/ 26-Feb-11 0:45am    
The question is very confusing.
Are you posting back the page on click of a radio button? And when you select Page 2 why does it goes to page one?
Do you have radio button against each image?
Sandeep Mewara 26-Feb-11 1:01am    
OP has replied with code.
Ankur\m/ 26-Feb-11 1:05am    
Oh Thanks!
Raj.rcr 26-Feb-11 1:15am    
Yes, its postback and it goes to page 1. Each image means, its a .tif image that includes 2 pages(images)
Ankur\m/ 26-Feb-11 1:32am    
How do you select the image (have checkbox or something)?

1 solution

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...

XML
<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.....
C#
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...
C#
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.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

/// <summary>
/// Summary description for MultiPageTifHandler
/// </summary>
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
 
Share this answer
 

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