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+中发生一般性错误。。到底是什么问题呀求高手出手相救呀。
//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+中发生一般性错误。。到底是什么问题呀求高手出手相救呀。
image = new Bitmap(stream);Bitmap有大小限制的,是你图片太大了?你注意任务管理器中的内存。另外,批量操作记得手动GC(GC.Collect();)。
//新建第二个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文件资源