c# winform验证码问题。。

来源:百度知道 编辑:UC知道 时间:2024/05/02 21:34:46
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(100, 35);//封装位图(定义大小)
private System.IO.MemoryStream ms = new System.IO.MemoryStream(); //内存流
private System.Drawing.Graphics gragh; //位图图片
private string code = "";
private void Form1_Load(object sender, EventArgs e)
{

}
private void button1_Click(object sender, EventArgs e)
{

Random ran = new Random(); //随机实例化
int number;
char code1;
f

在开发.NET应用中,使用 System.Drawing.Image.Save 方法而导致“GDI+ 中发生一般性错误”的发生,通常有以下三种原因:
1. 相应的帐户没有写权限。
解决方法:赋予 NETWORK SERVICE 帐户以写权限。
2. 指定的物理路径不存在。
解决方法:
在调用 Save 方法之前,先判断目录是否存在,若不存在,则创建。
if (!Directory.Exists(dirpath))
Directory.CreateDirectory(dirpath);
3. 保存的文件已存在并因某种原因被锁定。
解决方法:
重启IIS,解除锁定。并在代码中使用 using 语句,确保释放 Image 对象所使用的所有资源。