2011-10-03 31 views
2

我們正在使用System.Drawing.Graphics.Drawstring在圖像中寫入文本。下面的代碼顯示在asp.net中獲取圖形的單擊事件

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

的代碼需要一個鏡像文件,並寫入字符串(這裏:250),當用戶點擊250。現在,新的窗口應該拿開。

不知道如何獲得250的點擊事件?

請幫忙!謝謝

回答

0

它會更容易將圖像呈現到像一個DIV或SPAN容器,並添加一個onclick到容器:

<div onclick="doSomething();"> 
    <!-- rendered image here --> 
</div> 

您也可以考慮使用圖像映射,像這樣:

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> 
1

這是ASP.NET檢測到在圖像中繪製文本的點擊是可能的,但遠非理想。您應該使用div或其他html元素來呈現文本,方法是將其放置在圖像上,並使用javascript檢測點擊。

Text Blocks Over Image

相關問題