如何将ImageMap控件和热点添加到由数据库中的图像填充的网页上

我使用 BinaryWrite 方法显示 sql 中的 jpg gif 图像。图像已按预期加载。我想在该图像上添加热点。我无法将任何 ImageUrl 指向 ImageMap ,所以我认为主要问题就在于此。

我在 Page_Load 的后面代码中添加了 ImageMap 控件和相关的热点。没有成功。

我将控件放在Response.End()之前,因为此后不再执行任何代码。

在图像上未观察到热点。有什么方法可以完成此操作,因为我无法将图像作为打开文件嵌入服务器中。

这是我代码的最后一部分:

protected void Page_Load(object sender,EventArgs e)
{
    // After db connection and filling the data
    try
    {
        objAdapter.Fill(objTable);

        objRow = objTable.Rows[0];
        byte[] objData;
        objData = (byte[])objRow["Resim"];
        string name = (string)objRow["ResimAd"];
        char[] sep = { '.' };
        string[] nname;
        nname = name.Split(sep);
        int il = nname.Length;

        if (nname[il - 1] == "pdf" || nname[il - 1] == "PDF")
        {
            response.contenttype = "application/pdf";      
        }
        else if (nname[il - 1] == "xls" || nname[il - 1] == "XLS" || nname[il - 1] == "xlsx" || nname[il - 1] == "XLSX" || nname[il - 1] == "XLSB"
            || nname[il - 1] == "xlsb" || nname[il - 1] == "XLSM" || nname[il - 1] == "xlsm" || nname[il - 1] == "CSV" || nname[il - 1] == "csv")
        {
            response.contenttype = "application/vnd.ms-excel";      // excel dosya
        }
        else if (nname[il - 1] == "doc" || nname[il - 1] == "docx" || nname[il - 1] == "rtf")
        {
            response.contenttype = "application/vnd.ms-word";      
        }
        else
        {
            response.contenttype = "image";          
        }

        Response.AppendHeader("Content-Disposition","inline; filename=\"" + name + "\"");  
        Response.BinaryWrite(objData);
        Response.Flush();

        // Here I add ImageMap :
        ImageMap ImageMap1 = new ImageMap
        {
            HotSpotMode = HotSpotMode.Navigate,};
        Page.Controls.Add(ImageMap1);
        RectangleHotSpot hs1 = new RectangleHotSpot
        {
            Left = 0,Right = 500,Top = 0,Bottom = 500,AlternateText = "XXXXXXX",NavigateUrl = "~/Default.aspx"
        };
        ImageMap1.HotSpots.Add(hs1);
        Response.End();
    }
    catch (Exception ex)
    {
         labelError.Text = ex.ToString();
    }
}
beachboyll 回答:如何将ImageMap控件和热点添加到由数据库中的图像填充的网页上

我将ImageMap放在FormView中。将二进制图像数据绑定到它,然后将ImageUrl指向DataItem。因此,定义了ImageMap,并具有我想要添加的尽可能多的热点。完美的作品。

本文链接:https://www.f2er.com/3157564.html

大家都在问