validatorpic.aspx.cs

来自「asp.net 学生信息管理系统!可以作为课程设计来使用」· CS 代码 · 共 44 行

CS
44
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Drawing;
using System.Text; 


public partial class ValidatorPic : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string ImagePath = "~/igm/code.jpg";
        string strRandomint = this.GetRandomint();
        Session.Add("ValidatorCode", strRandomint);
        Bitmap bitMapImage = new System.Drawing.Bitmap(Server.MapPath(ImagePath));
        Graphics graphicImage = Graphics.FromImage(bitMapImage);
        graphicImage.SmoothingMode = SmoothingMode.HighSpeed;
        graphicImage.DrawString(strRandomint, new Font("Arial", 20, FontStyle.Bold), SystemBrushes.WindowText, new Point(5,5));
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        bitMapImage.Save(ms, ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType = "image/jpeg";
        Response.BinaryWrite(ms.ToArray());
        graphicImage.Dispose();
        bitMapImage.Dispose();
    }

    private string GetRandomint()
    {
        Random r = new Random();
        return r.Next(1000, 9999).ToString();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?