【问题标题】:save image files in C#在 C# 中保存图像文件
【发布时间】:2011-01-18 10:31:32
【问题描述】:

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

【问题讨论】:

  • 这个问题很模糊,你能提供更多关于你想要完成什么的细节吗?
  • 他想知道如何保存图像,这就是他得到的。
  • 嗨,这是真的,我的意思就是你说的。但我是她:)

标签: c# .net image save


【解决方案1】:
            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);
            }

【讨论】:

  • 添加一些解释,说明此答案如何帮助 OP 解决当前问题
【解决方案2】:
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);

【讨论】:

    【解决方案3】:

    如果您需要比 .Net Framework 开箱即用提供的更广泛的图像处理,请查看FreeImage 项目

    【讨论】:

      【解决方案4】:

      在 c# 中我们使用带有这些参数的 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);
      

      【讨论】:

        猜你喜欢
        • 2021-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-05
        • 2019-04-10
        相关资源
        最近更新 更多