请教用C#编写的验证码的代码

来源:百度知道 编辑:UC知道 时间:2024/06/17 05:50:07
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Png";
Response.BinaryWrite(ms.ToArray());
这几行代码是什么意思?起什么做用?

System.IO.MemoryStream ms = new System.IO.MemoryStream();
建立内存流对象ms用于保存图片
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
把图片以gif格式保存到ms中
Response.ClearContent();
清除所有内容输出
Response.ContentType = "image/Png";
设置输出内容类型为PNG格式图片
Response.BinaryWrite(ms.ToArray());
输出刚刚保存在ms中的图像

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing ;
using System.IO ;
using System.Drawing.Imaging;

namespace 验证码
{
public class 验证码
{
//无参数构造
public 验证码()
{

}

//带有生成字符个数的构造
//charNum是验证码中包含随机字符的个数
public 验证码(int charNum)
{
this.CharNum = charNum;
}

//带有验证码图片宽度和高度的构造
//width为验证码图片宽度,height为验证码图片高度
public 验证码(int width,int height)
{