private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Bitmap newBitmap=new Bitmap(36,16,PixelFormat.Format32bppArgb);
Graphics g=Graphics.FromImage(newBitmap);
g.FillRectangle(new SolidBrush(Color.White),new Rectangle(0,0,36,16));
Font textFont=new Font("Times New Roman",10);
Rectangle rectangle=new Rectangle(0,0,36,16);
Random rd=new Random();
int valationNo=1000+rd.Next(8999);
g.FillRectangle(new SolidBrush(Color.BurlyWood),rectangle);
g.DrawString(valationNo.ToString(),textFont,new SolidBrush(Color.Blue),rectangle);
newBitmap.Save(Server.MapPath("img") +"\\VaImage.gif",ImageFormat.Gif);
}上面是照书上抄的,下面书运行时的错误:GDI+ 中发生一般性错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。源错误:
行 41:
行 42:
行 43: newBitmap.Save(Server.MapPath("img") +"\\VaImage.gif",ImageFormat.Gif);
行 44:
行 45:
谢谢!!!
{
// 在此处放置用户代码以初始化页面
Bitmap newBitmap=new Bitmap(36,16,PixelFormat.Format32bppArgb);
Graphics g=Graphics.FromImage(newBitmap);
g.FillRectangle(new SolidBrush(Color.White),new Rectangle(0,0,36,16));
Font textFont=new Font("Times New Roman",10);
Rectangle rectangle=new Rectangle(0,0,36,16);
Random rd=new Random();
int valationNo=1000+rd.Next(8999);
g.FillRectangle(new SolidBrush(Color.BurlyWood),rectangle);
g.DrawString(valationNo.ToString(),textFont,new SolidBrush(Color.Blue),rectangle);
newBitmap.Save(Server.MapPath("img") +"\\VaImage.gif",ImageFormat.Gif);
}上面是照书上抄的,下面书运行时的错误:GDI+ 中发生一般性错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。源错误:
行 41:
行 42:
行 43: newBitmap.Save(Server.MapPath("img") +"\\VaImage.gif",ImageFormat.Gif);
行 44:
行 45:
谢谢!!!
newBitmap.Save(Server.MapPath("img") +"\\VaImage.gif",ImageFormat.Gif);
代码没错,问题是你少个img文件夹,建立img文件夹在项目根目录下即可
Server.MapPath("img") 值。是否是你需要的值?
创建虚拟目录完全是依靠VS自动生成的,没有其他动作。。
书上的代码可以在ASP.NET 1.1上运行的,但是我的机器,现在装过了VS2005BETA,就是说装了ASP.NET 2.0了,怎么办