Сохранять файлы изображений в С#
Как сохранить файлы изображений (такие как jpg или png) в С#?
Ответы
Ответ 1
в С# us the Image.Save Method с этими параметрами (строка 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);
Ответ 2
Image bitmap = Image.FromFile("C:\\MyFile.bmp");
bitmap.Save("C:\\MyFile2.bmp");
Вы можете использовать Сохранить метод из Image Class и быть в порядке, как показано выше. Метод сохранения имеет 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 project
Ответ 4
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);
}