tif图像中出现问题

tif图像中出现问题

本文介绍了单击单选按钮时.tif图像中出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我已将页码设置为嵌入图像.如果我选择页面"2"(第二个图像)并单击单选按钮,则会自动显示页面"1"(第一个图像).但是我希望每次单击单选按钮时都将相同的所选图像保留在页面上与之关联..

请任何人建议我..

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

推荐答案

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



在默认aspx后面的代码中有这个.....



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);

}



将一个新的aspx Webform添加到您的项目中,并将其命名为ImageViewer.在(ImageViewer.aspx.cs)后面的imageviewer代码中...具有此代码...



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();

}



现在,将一个新的类文件添加到名为MultiPageTifHandler的项目中,并在其中包含以下代码.



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;

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


这篇关于单击单选按钮时.tif图像中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:25