c#,vs2010.在一个picturebox控件中打开了一张本地的图片,做了修改后如何保存下来!

点击保存按钮后,覆盖原来的那张图片实现保存的源代码……

在保存按钮响应中添加以下语句:
FileInfo file = new FileInfo(fileName);//fileName为打开图像时的路径,使用FileInfo需要添加using System.IO;
if (file.Exists)//如果已存在,先删除再保存
{
file.Delete();
}
this.pictureBox1.Image.Save(fileName);
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-07-15
public string strFileName = null;
//打开
private void btnOpne_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "打开图片";
ofd.Filter = "jpg图片(*.jpg)|*.jpg";
ofd.ShowDialog();
if (ofd.FileName.Length != 0)
{
this.strFileName = ofd.FileName;
this.pictureBox1.ImageLocation = strFileName;
}
}
//保存
private void btnSave_Click(object sender, EventArgs e)
{
FileInfo fi = new FileInfo(strFileName);
if (fi.Exists)
{
fi.Delete();
this.pictureBox1.Image.Save(strFileName);
}
else
{
this.pictureBox1.Image.Save(strFileName);
}
}
//另存为
private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "jpg图片(*.jpg)|*.jpg";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{

this.pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);

}

}本回答被提问者采纳
第2个回答  2012-05-08
private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "jpg图片(*.jpg)|*.jpg";//其他格式也可加上去。
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{

this.pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);

}

}
相似回答