繁体   English   中英

在asp.net 3.5中使用图像控件显示多个图像

[英]Displaying multiple images with image control in asp.net 3.5

我想显示给定目录中的所有图像。 为此,我给了图像控件以显示图像,但是我想根据该目录中的图像自动使用该URL显示图像控件。 假设在我的目录中存在5个图像,则应该在我的按钮单击事件中显示5个图像控件。 我在button_click事件中编写了代码,该事件仅显示给定目录中的两个图像,如下所示:

protected void btncompare_Click(object sender, EventArgs e)
{
    Bitmap searchImage;
    searchImage = new Bitmap(@"D:\kc\ImageCompare\Images\img579.jpg");
    string dir = "D:\\kc\\ImageCompare\\Images";

    DirectoryInfo dir1 = new DirectoryInfo(dir);
    FileInfo[] files = null;

    files = dir1.GetFiles("*.jpg");

    double sim;
    foreach (FileInfo f in files)
    {
        sim = Math.Round(GetDifferentPercentageSneller(searchImage, new Bitmap(f.FullName)), 3);
        if (sim >= 0.95)
        {


            string imgPath = "Images/" + files[0];
            string imgPath1 = "Images/" + files[1];
            Image1.ImageUrl = "~/" + imgPath;
            Image2.ImageUrl = "~/" + imgPath1;
            Response.Write("Perfect match with Percentage" + " " + sim + " " + f);
            Response.Write("</br>");

        }
        else
        {

            Response.Write("Not matched" + sim);
            Response.Write("</br>");

        }

    }

}

似乎您要在此处将方形钉插入圆孔中。 图像控件旨在显示单个图像。

如果要显示多个图像,请使用多个图像控件。 我怀疑您不这样做的原因是因为您不知道将需要显示多少张图像。

如果遇到相同的问题,我会将图像目录的内容转换为可以绑定到中继器的内容。 每个ItemTemplate都将包含其自己的Image控件,使您可以显示所需数量的图像,而无需使用黑客手段。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM