在C#中保存图像文件

15 .net c# image save

我们如何在C#中保存图像文件(jpg或png等类型)?

Chr*_*nes 22

在c#us中,使用这些参数的Image.Save方法(字符串Filename,ImageFormat)

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);
Run Code Online (Sandbox Code Playgroud)


RSo*_*erg 18

Image bitmap = Image.FromFile("C:\\MyFile.bmp");
bitmap.Save("C:\\MyFile2.bmp");  
Run Code Online (Sandbox Code Playgroud)

你应该可以使用Image Class中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);
Run Code Online (Sandbox Code Playgroud)