[英]save image files in C#
我们如何在C#中保存图像文件(jpg或png等类型)?
in c# us the Image.Save Method with these parameters (string Filename , ImageFormat) 在c#us中,使用这些参数的Image.Save方法(字符串Filename,ImageFormat)
http://msdn.microsoft.com/en-us/library/9t4syfhh.aspx http://msdn.microsoft.com/en-us/library/9t4syfhh.aspx
Is that all you needed? 这就是你所需要的吗?
// 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");
You should be able to use the Save Method from the Image Class and be just fine as shown above. 你应该可以使用Image Class中的Save方法 ,如上图所示。 The Save Method has 5 different options or overloads...
保存方法有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.Png;
break;
case ".bmp":
format = ImageFormat.Bmp;
break;
}
pictureBox.Image.Save(sv.FileName, format);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.