save image files in C#

后端 未结 4 612
情歌与酒
情歌与酒 2020-12-16 14:48

How can we save image files (types such as jpg or png) in C#?

相关标签:
4条回答
  • 2020-12-16 15:11

    If you need more extensive image handling than the .Net Framework provides out of the box, check out the FreeImage project

    0 讨论(0)
  • 2020-12-16 15:17
                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);
                }
    
    0 讨论(0)
  • 2020-12-16 15:24

    in c# us the Image.Save Method with these parameters (string Filename , ImageFormat)

    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);
    
    0 讨论(0)
  • 2020-12-16 15:32
    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. The Save Method has 5 different options or overloads...

      //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);
    
    0 讨论(0)
提交回复
热议问题