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
Asked
Active
Viewed 2,563 times
0
-
Possible duplicate of [Adding text to an image file](http://stackoverflow.com/questions/709414/adding-text-to-an-image-file) – Carra Mar 23 '16 at 09:03
-
I am able to put to put an "X" mark on the image and display it but the problem is how to make this "X" mark appear on the same place I did the click – Dani Mar 23 '16 at 09:10
-
Is this web forms? – James Dev Mar 23 '16 at 09:12
-
Yes as I indicated I am working on an asp.net web page – Dani Mar 23 '16 at 09:26
-
Show us some code so we can help. – Carra Mar 23 '16 at 09:32
1 Answers
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