如何在C#中保存图像文件(jpg或png等类型)?
在 c# 中,我们使用具有这些参数(字符串 Filename 、 ImageFormat)的 Image.Save 方法
http://msdn.microsoft.com/en-us/library/9t4syfhh.aspx
这就是您所需要的吗?
// Construct a bitmap from the button image resource.
Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp");
// Save the image as a GIF.
bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);
Image bitmap = Image.FromFile("C:\\MyFile.bmp");
bitmap.Save("C:\\MyFile2.bmp");
您应该能够使用 Image Class 中的 Save Method 并且如上所示就可以了。 Save 方法有 5 种不同的选项或重载...
//Saves this Image to the specified file or stream.
img.Save(filePath);
//Saves this image to the specified stream in the specified format.
img.Save(Stream, ImageFormat);
//Saves this Image to the specified file in the specified format.
img.Save(String, ImageFormat);
//Saves this image to the specified stream, with the specified encoder and image encoder parameters.
img.Save(Stream, ImageCodecInfo, EncoderParameters);
//Saves this Image to the specified file, with the specified encoder and image-encoder parameters.
img.Save(String, ImageCodecInfo, EncoderParameters);
如果您需要比 .Net Framework 提供的开箱即用的更广泛的图像处理,请查看 FreeImage 项目
SaveFileDialog sv = new SaveFileDialog();
sv.Filter = "Images|*.jpg ; *.png ; *.bmp";
ImageFormat format = ImageFormat.Jpeg;
if (sv.ShowDialog() == DialogResult.OK)
{
switch (sv.Filter )
{
case ".jpg":
format = ImageFormat.Jpeg;
break;
case ".png":
format = ImageFormat.Png;
break;
case ".bmp":
format = ImageFormat.Bmp;
break;
}
pictureBox.Image.Save(sv.FileName, format);
}