[英]How to save a PictureBox image in varying formats?
I have a picture box that will contain an image generated during run-time.我有一个包含运行时生成的图像的图片框。 I need to save this image using a SaveFileDialog, for which I have found the fallowing code:
我需要使用 SaveFileDialog 保存此图像,为此我找到了以下代码:
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
pictureBox.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
}
This works however, I need to allow the user to specify in the FileDalog what format they want it to be saved as.但是,这有效,我需要允许用户在 FileDalog 中指定他们希望将其保存为什么格式。 The allowed formats for the user:
用户允许的格式:
Bitmap (*.bmp),位图 (*.bmp),
GIF (*.gif), GIF (*.gif),
JPEG (*.jpg), JPEG (*.jpg),
and PNG (*.png).和 PNG (*.png)。 Any examples or recommendations on how to accomplish this would be much appreciated.
任何关于如何实现这一点的示例或建议将不胜感激。
Somthing like this could be a good place to start像这样的事情可能是一个很好的起点
var fd = new SaveFileDialog();
fd.Filter = "Bmp(*.BMP;)|*.BMP;| Jpg(*Jpg)|*.jpg";
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
switch (Path.GetExtension(fd.FileName))
{
case ".BMP":
pictureBox.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case ".Jpg":
pictureBox.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
default:
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.