0

I have a web page where it displays an image (any car image to be exact),my problem is that i need this page to locate car damage by clicking on the image. For example if I click somewhere on the image, an "X" mark appears in the place I clicked. So my point is how set the "X" mark when mouse is clicked. I guess it is something related to the coordinates of the image.Is this possible to do? If yes can anyone help me? Thanks

Dani
  • 53
  • 2
  • 7

1 Answers1

0

Actually I found the answer for my own question

protected void ImageMap1_Click(object sender, ImageClickEventArgs e){

    int x = int.Parse(e.X.ToString());
    int y = int.Parse(e.Y.ToString());

    Bitmap bitMapIm = new System.Drawing.Bitmap(Server.MapPath("~/carImage.jpg"));
    Graphics graphicIm = Graphics.FromImage(bitMapIm);
    Pen penRed = new Pen(Color.Red, 3);
    graphicIm.DrawString("X", new Font("Arial", 25, FontStyle.Bold), Brushes.Red, x, y);
    bitMapIm.Save(Server.MapPath("~/carImage1.jpg"), ImageFormat.Jpeg);
    graphicIm.Dispose();
    bitMapIm.Dispose();
    ImageMap1.ImageUrl = "~/carImage1.jpg";
}
Dani
  • 53
  • 2
  • 7
  • Careful: you seem to be editing the one "carImage.jpg" that will probably be shared by *all* visitors of your site. Save the image to a filename related to the incident ID or something else specific to this one report. – Hans Kesting Mar 23 '16 at 10:00
  • @HansKesting yes i am aware of this. This was just a testing code just to make sure i reached my point. – Dani Mar 23 '16 at 10:49
  • Careful about using fonts, the centre of the X may not represent the point where the user clicked. If you offset the X,Y to match the click point, the offset will change with the font type and size. it may be better to draw two lines with the centre intersecting the mouse click X and Y points. – Phill Sep 27 '18 at 16:15