简体   繁体   中英

How do I add ImageMap control and hotspots to my web page filled by image from database

Im displaying jpg or gif images from sql using BinaryWrite method. Image is loaded as expected. I want to add hotspots on that image. I cannot point any ImageUrl to the ImageMap , so I think main problem lies there.

I added ImageMap control and associated hotspots on Page_Load in code behind. No success.

I put the control before Response.End() , since thereafter no more code is executed.

No hotspot is observed on the image. Is there any way to accomplish this as I can not embed the images as open files in the server.

Here is last part of my code:

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

I put the ImageMap in a FormView. Tied the binary imagedata to it, and pointed the ImageUrl to the DataItem. So, the ImageMap is defined, with as many hotspots as I want addable. Works perfect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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