我已经一个图像显示在我的应用程序的图片框控件。现在,当我的应用程序正在运行且图像已被应用程序使用时,我想更新该图像。如何将图像文件保存到应用程序中?
我用这条线的代码更新我的logo图片:更新的代码
public void showRow()
{
string _fileName = Application.StartupPath + "\\Logo" + ".png";
using (var stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read))
{
var img = Image.FromStream(stream);
pbStoreLogo.Image = img;
}
}
private void btnsave_Click(object sender, EventArgs e)
{
using (var m = new MemoryStream())
{
pbStoreLogo.Image.Save(m,System.Drawing.Imaging.ImageFormat.Png);
var img = Image.FromStream(m);
img.Save(Application.StartupPath + "\\Logo" + ".png");
}
}
它通过例外:A generic error occurred in GDI+.
所以,请建议我如何在运行改变我的形象或者为我提供这个例外的解决方案。
更新或写?两者都是两种不同的操作。你想刷新picturebox中的现有图像吗?或者你想将pb图像保存到某个文件? – nawfal
我想将pb图像保存到当前正在运行的应用程序中使用的现有文件。 –