C#用.png中的Button1保存Pitcherbox1
本文关键字:保存 Pitcherbox1 Button1 中的 png | 更新日期: 2023-09-27 17:58:56
我一直在尝试将图像保存在pictureBox1中。我想做的是让人们可以通过点击我的"另存为"按钮来"保存"pictureBox1中的图像。
我正在使用带有C#的Visual Studio 2010
这就是我目前所拥有的:
private void Button2_Click(System.Object sender, System.EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Png Image|*.jpg";
saveFileDialog1.Title = "Save an Image File";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
pictureBox1.Image = new Bitmap ("c:/avatar.png");
{
SaveFileDialog dialog = new SaveFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image.Save(@"C:'Documents and Settings'.Png", System.Drawing.Imaging.ImageFormat.Png);
}
}
}
我不确定你在用代码做什么,里面似乎有很多错误。我会这样做:
private void Button2_Click(System.Object sender, System.EventArgs e)
{
if (pictureBox.Image != null)
{
using {var dialog = new SaveFileDialog())
{
dialog.Title = ...
saveFileDialog1.Filter = "Png Image|*.png";
...other properties...
if (dialog.ShowDialog == DialogResult.OK)
{
pictureBox.Image.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Png)
}
}
}
}