How can we save image files (types such as jpg or png) in C#?
Asked
Active
Viewed 6.4k times
17
-
4This question is very vague, can you provide more detail as to what you're trying to accomplish? – Chris Conway Feb 18 '10 at 17:18
-
3He wanted to know how to save an image, thats what he got. – Chris Jones Feb 18 '10 at 17:28
-
4hi, it's true, my means was what that you said. but i'm she :) – Feb 18 '10 at 17:33
4 Answers
25
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);

Chris Jones
- 2,630
- 2
- 21
- 34
19
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);

RSolberg
- 26,821
- 23
- 116
- 160
0
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);
}
-
Add some explanation with answer for how this answer help OP in fixing current issue – ρяσѕρєя K Mar 27 '17 at 05:53