最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

制作验证码图片

来源:动视网 责编:小OO 时间:2025-10-08 00:45:11
文档

制作验证码图片

usingSystem.Drawing;usingSystem.Drawing.Imaging;usingSystem.Drawing.Drawing2D;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){Response.ContentType="image/jpeg";//输出流的HTTPMIME类型。默认值为“text/html”。Response.C
推荐度:
导读usingSystem.Drawing;usingSystem.Drawing.Imaging;usingSystem.Drawing.Drawing2D;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){Response.ContentType="image/jpeg";//输出流的HTTPMIME类型。默认值为“text/html”。Response.C
using System.Drawing;

using System.Drawing.Imaging;

using System.Drawing.Drawing2D;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        Response.ContentType = "image/jpeg";//输出流的 HTTP MIME 类型。默认值为“text/html”。

        Response.Clear();//清除缓冲区流中的所有内容输出。

        Response.BufferOutput = true;//获取或设置一个值,该值指示是否缓冲输出并在处理完整个页之后发送它。

        Font rectangleFont = new Font("Arial", 10, FontStyle.Bold);//使用指定的大小和样式初始化新 System.Drawing.Font。

        int height = 25;//图片的高度

        int width = 150;//图片的宽度

        Random r = new Random();//使用与时间相关的默认种子值,初始化 System.Random 类的新实例。

        int x = r.Next(75);//返回一个小于所指定最大值的非负随机数。

        int a = r.Next(155);

        int x1 = r.Next(100);

        Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);//用指定的大小和格式初始化 System.Drawing.Bitmap 类的新实例。

        Graphics g = Graphics.FromImage(bmp);//此方法为指定的 System.Drawing.Image 返回一个新的 System.Drawing.Graphics。

        g.SmoothingMode = SmoothingMode.AntiAlias;//指定是否将平滑处理(消除锯齿)应用于直线、曲线和已填充区域的边缘。

        g.Clear(Color.Coral);//清除整个绘图面并以指定背景色填充。

        //在指定位置并且用指定的 System.Drawing.Brush 和 System.Drawing.Font 对象绘制指定的文本字符串。

        g.DrawString("ASP.NET 验证码", rectangleFont, SystemBrushes.WindowText, new PointF(16, 5));

        bmp.Save(Response.OutputStream, ImageFormat.Jpeg);//将此图像以指定的格式保存到指定的流中。

        g.Dispose();//释放由 System.Drawing.Graphics 使用的所有资源。

        bmp.Dispose();//释放由 System.Drawing.Image 使用的所有资源。

        Response.Flush();//向客户端发送当前所有缓冲的输出。

    }

}

文档

制作验证码图片

usingSystem.Drawing;usingSystem.Drawing.Imaging;usingSystem.Drawing.Drawing2D;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){Response.ContentType="image/jpeg";//输出流的HTTPMIME类型。默认值为“text/html”。Response.C
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top