我在C# Winforms应用程序中有一个对话框。我想保存图像。但每次我单击保存按钮时,我都会得到一个错误
gdi+中出现一般错误
这是我保存图像的代码:
var SavedFileName = string.Format(@"{0}.png", Guid.NewGuid());
var path = Application.StartupPath + "/passport/" + SavedFileName.ToString();
if(passportsize.Image == null)
{
SavedFileName = "";
}
else
{
passportsize.Image.Save(path,System.Drawing.Imaging.ImageFormat.Png);
}
发布于 2018-12-14 05:36:14
尝试使用反斜杠而不是正斜杠。"\\passport
\“而不是"/passport/”
发布于 2018-12-14 13:51:09
您还没有提供完整的消息,所以我不能确定,但是很可能创建图像的源流已经被处理掉了,但是图像仍然绑定到它。
在创建映像时,您应该克隆它。例如:
private Image ImageFromBytes(byte[] imageBytes)
{
using (var ms = new MemoryStream(imageBytes))
{
using (var image = Image.FromStream(ms))
{
return (Image)image.Clone();
}
}
}
然后,当您稍后来保存它时,您应该不会遇到任何问题。
https://stackoverflow.com/questions/53770284
复制相似问题