求高手帮忙看下下面的方法是干嘛的,顺便每一行都标上注释,50分辛苦费双手奉上

qiyue444865262 2012-03-14 01:56:31
public void CreateImage(string str_ValidateCode)
{
int bmpWidth = str_ValidateCode.Length * 9;
int bmpHight = 0x12;
Random newRandom = new Random();
Bitmap theBitmap = new Bitmap(bmpWidth, bmpHight);
Graphics theGraphics = Graphics.FromImage(theBitmap);
theGraphics.Clear(Color.White);
Font theFont = new Font("Verdana", 9f);
for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++)
{
string str_char = str_ValidateCode.Substring(int_index, 1);
Brush newBrush = new SolidBrush(this.GetRandomColor());
Point thePos = new Point(int_index * 8, 2);
theGraphics.DrawString(str_char, theFont, newBrush, (PointF) thePos);
}
MemoryStream ms = new MemoryStream();
theBitmap.Save(ms, ImageFormat.Png);
base.Response.ClearContent();
base.Response.ContentType = "image/Png";
base.Response.BinaryWrite(ms.ToArray());
theGraphics.Dispose();
theBitmap.Dispose();
base.Response.End();
}
...全文
58 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiyue444865262 2012-03-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bdmh 的回复:]
C# code

public void CreateImage(string str_ValidateCode)
{
int bmpWidth = str_ValidateCode.Length * 9;//str_ValidateCode的长度乘9
int bmpHight = 0x12;
……
[/Quote]
THANK YOU 发帖的时候没注意 只有40分 不好意思啊
bdmh 2012-03-14
  • 打赏
  • 举报
回复

public void CreateImage(string str_ValidateCode)
{
int bmpWidth = str_ValidateCode.Length * 9;//str_ValidateCode的长度乘9
int bmpHight = 0x12;
Random newRandom = new Random();//随机数
Bitmap theBitmap = new Bitmap(bmpWidth, bmpHight);//新建一个bitmap对象
Graphics theGraphics = Graphics.FromImage(theBitmap);//获得上面对象的graphic
theGraphics.Clear(Color.White);//填充白底色
Font theFont = new Font("Verdana", 9f);//字体
//下面是在theGraphics上面画文字
for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++)
{
string str_char = str_ValidateCode.Substring(int_index, 1);
Brush newBrush = new SolidBrush(this.GetRandomColor());
Point thePos = new Point(int_index * 8, 2);
theGraphics.DrawString(str_char, theFont, newBrush, (PointF)thePos);
}
MemoryStream ms = new MemoryStream();//创建内存流
theBitmap.Save(ms, ImageFormat.Png);//位图保存至流

//下面调用基类的方法,自己查去
base.Response.ClearContent();
base.Response.ContentType = "image/Png";
base.Response.BinaryWrite(ms.ToArray());
theGraphics.Dispose();//释放
theBitmap.Dispose();//释放
base.Response.End();
}

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧