我将JPG图片保存至数据库:   MemoryStream ms = new MemoryStream();
            pictureBox.Image.Save(ms,ImageFormat.Jpeg);在运行到 "pictureBox.Image.Save(ms,ImageFormat.Jpeg);"时,系统报错:
“c# A generic error occurred in GDI+.”请问是什么原因(换成bmp,gif等格式也不行)?

解决方案 »

  1.   

    1、检查文件路径是否正确。
    2、确认你是否有权限读写图片所在的文件夹。
    3、http://www.eggheadcafe.com/aspnet_answers/NETFrameworkdrawing/Jan2006/post25815576.aspI found the problem: I was reading the image from the database using a    
    memorystream object to convert it from an array of bytes to a bitmap. The    
    memory stream object then was destroyed and hence the GDI+ specialty that    
    the creating stream must live as long as the bitmap was violated. --> That's    
    why I got the GDI+ error when trying to convert the same bitmap again later    
    to Base64.    
    Solution: use an object variable for the memorystream to ensure it lives as    
    long as the bitmap object itself, actually I am recycling it to convert the    
    image back to Base64    
    Let's see if the converted image is still good :)    
    Martin
      

  2.   

    如果你是直接在picturebox中进行画的,并没有初始化Image对象的话,是不能用
    pictureBox.Image.Save(ms,ImageFormat.Jpeg);
    方法来获取数据。相应的替换方法是
    方法一、通过抓屏,形成Bitmap对象,然后再调用Bitmap.Save方法获得图像数据;方法二、给PictureBox初始化Image对象,所有操作也通过Image对象完成,这样你在通过pictureBox.Image.Save的时候不会出错。
      

  3.   

    MemoryStream ms = new MemoryStream();
                pictureBox.Image.Save(ms,server.path("")+"\\ImageFormat.Jpeg");
      

  4.   

    http://support.microsoft.com/?id=814675
      

  5.   


    MemoryStream ms = new MemoryStream();
    pictureBox.Image.Save(ms,server.path("")+"\\ImageFormat.Jpeg");
      

  6.   

    我知道了,是要先做一步pictureBox.Load(....)的动作,
    再做pictureBox.Image.Save(ms,ImageFormat.Jpeg)就可以了