2011-08-09 49 views

回答

0

我想你問如何使自己與asp.net不使用外接。這是我使用和非常有效的

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Drawing; 

public partial class AntiSecuirtyImageDrawPage : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     this.returnNumer(); 
    } 

    private void returnNumer() 
    { 

     Random num1 = new Random(); 

     Random num2 = new Random(); 

     int numQ1 = 0; 

     int numQ2 = 0; 

     string QString = null; 

     numQ1 = num1.Next(1, 90); 

     numQ2 = num1.Next(1, 9); 

     QString = numQ1.ToString() + " + " + numQ2.ToString() + " = "; 

     Session["ABQAnswer"] = numQ1 + numQ2; 

     Bitmap bitmap = new Bitmap(num1.Next(70, 125), 22); 

     Graphics Grfx = Graphics.FromImage(bitmap); 

     Font font = new Font("Arial", 17, FontStyle.Bold, GraphicsUnit.Pixel); 

     Rectangle Rect = new Rectangle(0, 0, 125, 50); 

     Grfx.FillRectangle(Brushes.DarkBlue, Rect); 

     Grfx.DrawRectangle(Pens.PeachPuff, Rect); 

     // Border 

     Grfx.DrawString(QString, font, Brushes.White, 0, 0); 

     Response.ContentType = "Image/jpeg"; 

     bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); 

     bitmap.Dispose(); 

     Grfx.Dispose(); 

    } 
} 

我怎麼稱呼它

<div id="ABQImg" style="position: absolute; left: 420px; top: 235px; width: 125px; 
      z-index: 44; height: 22px; line-height: 22px; text-align: right;"> 
      <asp:Image ID="imgABQ" BorderWidth="0px" runat="server" ImageUrl="~/AntiSecuirtyImageDrawPage.aspx" /> 
     </div>