intCount++;
                        //lblTag.Text = "正在导出第 " + intCount.ToString() + " 张照片,共有" + intAllCount.ToString() + "张";
                        lblTag.Text = intCount.ToString();
                        string strPath = txtPath.Text + "\\" + people.StrName + "_" + people.StrIdentify + "_" + intCount.ToString() + ".jpg";
                        byte[] picture = (byte[])people.Picture;
                        
                        //保存图片
                        if (picture != null && picture.Length > 1)
                        {
                         
                            MemoryStream stream = null;
                            Image image = null;
                            try
                            {
                                stream = new MemoryStream(picture, true);
                                stream.Write(picture, 0, picture.Length);
                                image = new Bitmap(stream);                                image.Save(strPath);                                
                            }
                            finally
                            {
                                image.Dispose();
                                image = null;
                                stream.Dispose();
                                stream.Close();                                
                            }
                            
                            //MessageBox.Show("照片导出成功!", "提示信息!");
                        }
                        else
                        {
                            MessageBox.Show(people.StrName + "照片不存在!", "提示信息");
                        }
      一共有4万多张照片只导出了480张的时候就报错了。。错误就是image = new Bitmap(stream);[/GDI+中发生一般性错误。。到底是什么问题呀求高手出手相救呀。

解决方案 »

  1.   

    http://wenku.baidu.com/view/bed35369011ca300a6c390e6.html
      

  2.   

    是内存不足,我也遇到过。
    image = new Bitmap(stream);Bitmap有大小限制的,是你图片太大了?你注意任务管理器中的内存。另外,批量操作记得手动GC(GC.Collect();)。
      

  3.   

    内存不足肯定排除掉,原因是你的finally部分已经释放掉资源。image =Image.FromStream(stream); //试一下Bitmap 对象或一个 图像 对象从一个文件, 构造时该文件仍保留锁定对于对象的生存期。 因此, 无法更改图像并将其保存回它产生相同的文件。
      

  4.   

    如果不行的话,用镜像bitmap。                                Bitmap bmp = new Bitmap(openFileDialog1 .FileName );
                    //新建第二个bitmap类型的bmp2变量,我这里是根据我的程序需要设置的。
                      Bitmap bmp2 = new Bitmap();//新的镜像图片
                     //将第一个bmp拷贝到bmp2中
                       Graphics draw = Graphics.FromImage(bmp2);
                    draw.DrawImage(bmp,0,0);
                    image= (Image)bmp2 ;//读取bmp2到image             
                    image.Save(strPath);   
                    openFileDialog1.Dispose();
                    draw.Dispose();
                    bmp.Dispose();//释放bmp文件资源
      

  5.   

    楼主把你的Try,Catch去掉。再执行,就会发现原因了。
      

  6.   

    使用using可以自动清理内存吗?