Reputation: 19003
We are writing a text in an image using System.Drawing.Graphics.Drawstring
. Below code is shown
Bitmap bitMapImage = new System.Drawing.Bitmap(@"D:\ABC\Chart1.png");
Graphics graphicImage = Graphics.FromImage(bitMapImage);
//Smooth graphics is nice.
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
String drawString = "250";
Font drawFont = new Font("Arial", 12,FontStyle.Bold);
SolidBrush drawBrush = new SolidBrush(Color.White);
PointF drawPoint= new PointF(169.0F, 85.0F); .
graphicImage.DrawString(drawString, drawFont, drawBrush, drawPoint);
//Set the content type
Response.ContentType = "image/jpeg";
//Save the new image to the response output stream.
bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);
//Clean house.
graphicImage.Dispose();
bitMapImage.Dispose();
The code takes an imagefile and writes the string (here:250).Now when user clicks 250, the new window should get open.
Not sure how to get the click event of 250?
Please help! Thanks
Upvotes: 2
Views: 239
Reputation: 46067
It would be easier to render the image to a container like a DIV or SPAN, and add an onclick to container:
<div onclick="doSomething();">
<!-- rendered image here -->
</div>
You might also look into using an Image Map, like this:
function foo() {
alert("Hello World!")
}
<img src="/images/someimage.png" usemap="#somemap" />
<map name="somemap">
<area coords="0,0,82,126" onclick="foo()" nohref="true" href="#" />
</map>
Upvotes: 0
Reputation: 35146
This is ASP.NET detecting a click on drawn text in an image is possible but far from ideal. You should instead render text using a div or other html element by positioning it over the image and detect clicks on the that instead using javascript.
Upvotes: 1