我使用以下方法将图像加载到 Picture Box 中:
picturebox1.Image = Image.FromFile()
我使用以下方法保存它:
Bitmap bm = new Bitmap(pictureBox1.Image);
bm.Save(FileName, ImageFormat.Bmp);
创建新文件时它工作得很好,但是当我尝试替换现有图像时,会抛出以下运行时错误:
A generic error occurred in GDI+
那么我该怎么做才能解决这个问题呢??
最佳答案
那是因为你的picturebox1.Image
使用了图片文件,尝试将它保存到不同的文件路径:
picturebox1.Image = Image.FromFile(FileName);
Bitmap bm = new Bitmap(pictureBox1.Image);
bm.Save(@"New File Name", ImageFormat.Bmp);
编辑:您还可以在第一处添加图像的副本,例如:
picturebox1.Image = new Bitmap(Image.FromFile(FileName));
Bitmap bm = new Bitmap(pictureBox1.Image);
bm.Save(FileName, ImageFormat.Bmp);//no error will occurs here.
关于c# - GDI+ 中发生一般性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7105561/