关于Hanler生成位图BMP的问题。
context.Response.ContentType = "image/bmp";
Bitmap b = new Bitmap(200, 60);
string sPassed = string.Empty;
Graphics g = Graphics.FromImage(b);
g.FillRectangle(new SolidBrush(Color.White), 0, 0, 200, 60);
Font font = new Font(FontFamily.GenericSansSerif, 48, FontStyle.Bold, GraphicsUnit.Pixel);
Random r = new Random();
string letters = "ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz123456789";//L l I i O o 0 剔除
string letter = "";
string valicode = "";
for (int x = 0; x < 4; x++)
{
letter = letters.Substring(r.Next(0, letters.Length - 1), 1);
g.DrawString(letter, font, new SolidBrush(Color.Black), x * 38, r.Next(0, 15));
}
b.Save(context.Response.OutputStream, ImageFormat.Bmp);
context.Response.End();
不知道为什么 会报错。我是拿来做验证码的,我看CSDN登录的验证码就是BMP格式的。求指教
------解决方案--------------------
context.Response.Clear();