Link to home
Start Free TrialLog in
Avatar of Eamon
EamonFlag for Ireland

asked on

How to load one image on top of another image in Asp.net

Hi,

Basically I'm looking for a way to create the following in ASP.Net... http://www.geometricglobal.com/Corporate/Locations/index.aspx using Asp.Net.

I'm currently wrecking my head on ways around loading images on top of other images in asp.net. I have a main image and I want to place a marker image on top using X and Y coordinates which I pull from a database. When I hover over the marker image I want a popup to appear to the user.
I managed to get the marker images loading using a handler file........see code, but i can figure out how will i get the hover to work.

Also I want to allow the user to click on the main map image and a marker image will appear on the coordinates the user clicked on.

Thanks

<%@ WebHandler Language="C#" Class="MapHandler" %>
 
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Data;
public class MapHandler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        CreateImage(context);
    }
    private void CreateImage(HttpContext context)
    {
        System.Drawing.Image image = System.Drawing.Image.FromFile(context.Server.MapPath(@"BuildingA_Front.jpg"));
        System.Drawing.Image imgSold = System.Drawing.Image.FromFile(context.Server.MapPath(@"sold_marker.png"));
        
        Graphics _sold = Graphics.FromImage(imgSold);
        Graphics g = Graphics.FromImage(image);
        Pen p = new Pen(Color.Red);
       // please create rectangle according to the position whith their data from database.
        int x = 0;
        int y = 0;
        foreach (DataRow dr in GetTable().Rows)
        {
            
            x = (dr[0] == null) ? 0 : int.Parse(dr[0].ToString());
            y = (dr[1] == null) ? 0 : int.Parse(dr[1].ToString());
            Point pt = new Point(x,y);
            //Rectangle r = new Rectangle(x, y, 8, 8);
            //Brush b = new System.Drawing.SolidBrush(Color.Red);
            g.DrawImage(imgSold, pt);
            //g.FillEllipse(b, r);
        }
 
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        context.Response.ClearContent();
        context.Response.ContentType = "image/Jpeg";
        context.Response.BinaryWrite(ms.ToArray());
        g.Dispose();
        image.Dispose();
    }
    DataTable GetTable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("P_X", typeof(float)));
        dt.Columns.Add(new DataColumn("P_Y", typeof(float)));
        //dt.Rows.Add(10, 50);
        dt.Rows.Add(80, 100);
        //dt.Rows.Add(150, 80);
        return dt;
    }
    public bool IsReusable {
        get {
            return false;
        }
    }
 
}

Open in new window

conditional-marker.png
floor-plan-thumb.jpg
Avatar of bhermer
bhermer

Why not load the second image (png with transparancy would be good) into a div with a z-order higher that the div the main image is in. you can position the top div using coordinates based on the top and left position on the main div relative to the page
addition, you get the relative position by tracking the mouse position on the page using javascript, loads of script around that will give you that for all main browsers (bear in mind, using the png in IE6 on a dynamic layer/div with look bad, and you cant use the microsoft IE png fix because it only works on images within divs with position:absolute)
Avatar of Eamon

ASKER

I wonder could I use an ImageMap control.
ASKER CERTIFIED SOLUTION
Avatar of bhermer
bhermer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eamon

ASKER

I have created a custom usercontrol which contains a Imagebutton and a panel. I dynamically load the usercontrol into a div with the z-index higher than the main div.  

I have added attributes to the imagebutton on the usercontrol for onmouseover and onclick. On the mouseover i display the panel for the current image.

Avatar of Eamon

ASKER

Thanks for the heads up on the div layers.