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: 
 
谢谢!!!

解决方案 »

  1.   

    先将: Server.MapPath("img")  放到一个string中,看一下它的值是什么.
      

  2.   

    C:\Inetpub\wwwroot\SuperTest\img我开了这个目录的了
      

  3.   

    错误产生在这句
    newBitmap.Save(Server.MapPath("img") +"\\VaImage.gif",ImageFormat.Gif);  
    代码没错,问题是你少个img文件夹,建立img文件夹在项目根目录下即可
      

  4.   

    如果有img文件夹的话,然后把VaImage.gif改名为VaImage111.gif,别让他重名,如下newBitmap.Save(Server.MapPath("img") +"\\VaImage111.gif",ImageFormat.Gif);
      

  5.   

    设置断点看一看
    Server.MapPath("img") 值。是否是你需要的值?
      

  6.   

    我创建了这个IMG目录,用Response.Write(Server.MapPath("img"))看到的是:C:\Inetpub\wwwroot\SuperTest\img
      

  7.   

    给wwwroot文件夹分配一个everyone权限...
      

  8.   

    我是在win2000单机板上测试上面那段程序的
    创建虚拟目录完全是依靠VS自动生成的,没有其他动作。。
      

  9.   

    !!!!!!!!!!!!!!!!!!!!!!我找到了原因,但是却没有办法解决:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    书上的代码可以在ASP.NET 1.1上运行的,但是我的机器,现在装过了VS2005BETA,就是说装了ASP.NET 2.0了,怎么办