可能的重复:
使用 savefiledialog 保存图像时出现问题 https://stackoverflow.com/questions/11053398/issue-while-saving-image-using-savefiledialog
我在 C# 中使用 Windows 窗体。我应该如何使用 saveFileDialog?我有图片框,图片框上有一张图像,我想保存它。加载的图像是bmp。我想将其保存为 4 种格式之一:bmp、jpeg、png、tiff。我在 MDSN 上阅读了一些注释,也尝试过,但我可能做错了什么。那请问应该怎么写呢?
方法应该怎么写private void saveFileDialog1_FileOk(对象发送者,CancelEventArgs e)以及财产应该是什么样子保存文件对话框.Filter?
Thanks
EDIT:
我尝试过的:
使用 savefiledialog 保存图像时出现问题 https://stackoverflow.com/questions/11053398/issue-while-saving-image-using-savefiledialog
EDIT2:
我尝试过这个过滤器
Filter = bmp (*.bmp)|*.bmp|jpeg (*.jpeg)|*.jpeg|png (*.png)|*.png|tiff (*.tiff)|*.tiff
您可以像这样使用 SaveFileDialog:
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Images|*.png;*.bmp;*.jpg";
ImageFormat format = ImageFormat.Png;
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string ext = System.IO.Path.GetExtension(sfd.FileName);
switch (ext)
{
case ".jpg":
format = ImageFormat.Jpeg;
break;
case ".bmp":
format = ImageFormat.Bmp;
break;
}
pictureBox1.Image.Save(sfd.FileName, format);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)