我正在尝试将我从位图创建的图像保存在项目的给定路径中,但出现此错误:Additional information: A generic error occurred in GDI+.
这是代码:
public void SaveCaptchaImage(string name)
{
Bitmap image = new Bitmap(128, 64);
string path = "/content/images";
if (System.IO.File.Exists(path + name))
System.IO.File.Delete(path + name);
using (Pen myPen = new Pen(Color.Red, 5))
using (Brush myBrush = new SolidBrush(Color.Silver))
using (Font myFont = new Font("Arial", 16))
using (Graphics graphObject = Graphics.FromImage(image))
{
graphObject.FillRectangle(myBrush, new Rectangle(0, 0, 128, 64));
graphObject.DrawString(GetRandomCaptcha(), myFont, myBrush, new Point(20, 20));
image.Save(path + name + ".png", ImageFormat.Png);
}
image.Dispose();
}
异常发生在这一行:
image.Save(path + name + ".png", ImageFormat.Png);
我能做些什么来解决这个问题?
编辑:我不明白为什么我被否决了,但是好的。