[英]Error : A generic error occurred in GDI+. while saving Image
虽然我试图保存图像获取此错误A generic error occurred in GDI+
我搜索此错误并检查此文件夹的写入权限,并检查该图像文件未被其他任何东西使用(包括我的代码)但是我我试图保存图像仍然得到相同的错误,错误在哪里
public partial class AdsMaster : Form
{
OpenFileDialog ofd=null;
public AdsMaster()
{
InitializeComponent();
}
private void browseButton_Click(object sender, EventArgs e)
{
ofd = new OpenFileDialog();
ofd.Filter = "image files|*.jpg;*.jpeg;*.gif;*.png;*.bmp";
DialogResult dr = new DialogResult();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Image img = new Bitmap(ofd.FileName);//create the bitmap
string imgName = ofd.SafeFileName;
txtImagePath.Text = imgName;
pictureBox1.Image = img.GetThumbnailImage(350, 350, null, new IntPtr());
ofd.RestoreDirectory = true;
img.Dispose();
}
}
private void saveImage_Click(object sender, EventArgs e)
{
String str = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string path = str + "\\Image\\";
Image img = new Bitmap(ofd.FileName);
string imgName = ofd.SafeFileName;
try
{
img.Save(path + imgName); //getting error at this line
MessageBox.Show("Image is saved");
img.Dispose(); // dispose of your image
}
catch(Exception err)
{
MessageBox.Show(err.Message.ToString());
}
}
}
我认为这里的问题可能是由于你打电话时在原始图像上放置了一个锁
Image img = new Bitmap(ofd.FileName);
以下应该做的伎俩
private void saveImage_Click(object sender, EventArgs e)
{
string str = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string path = str + "\\Image\\";
string imgName = ofd.SafeFileName;
try
{
File.Copy(ofd.FileName, path + imgName);
MessageBox.Show("Image is saved");
}
catch (Exception err)
{
MessageBox.Show(err.Message.ToString());
}
}
我通过更改文件名和存储文件的路径来解决此错误。 你需要检查其中一个 -
1- FileName应该不同/不应与已存在于要存储新文件/图像的位置上的其他文件名匹配。
2-从操作系统驱动器更改新文件的(保存)位置。 尽量避免将新文件/ Image存储在已安装操作系统的驱动器上。
下面的代码适合我
IWebdriver driver;
driver = new ChromeDriver("G:\\Selenium_Csharp\\Jar\\chromedriver_win32");
driver.Navigate().GoToUrl("http://www.gmail.com");
driver.Manage().Window.Maximize();
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile("e:\\pande", System.Drawing.Imaging.ImageFormat.Jpeg);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.