2010-02-18 53 views
15

Làm cách nào để lưu các tệp hình ảnh (các loại như jpg hoặc png) trong C#?lưu các tập tin hình ảnh trong C#

+4

Câu hỏi này rất mơ hồ, bạn có thể cung cấp thêm chi tiết về những gì bạn đang cố gắng hoàn thành không? –

+3

Anh ấy muốn biết cách lưu hình ảnh, đó là những gì anh ấy có. –

+4

hi, đó là sự thật, phương tiện của tôi là những gì bạn nói. nhưng tôi là cô ấy :) –

Trả lời

22

trong C# chúng ta phương pháp Image.Save với các thông số (string Tên file, ImageFormat)

http://msdn.microsoft.com/en-us/library/9t4syfhh.aspx

Có phải đó là tất cả các bạn cần thiết?

// 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); 
18
Image bitmap = Image.FromFile("C:\\MyFile.bmp"); 
bitmap.Save("C:\\MyFile2.bmp"); 

Bạn sẽ có thể sử dụng Save Method từ Image Class và được chỉ tốt như trình bày ở trên. Lưu Phương pháp có 5 tùy chọn khác nhau hoặc quá tải ...

//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

Nếu bạn cần xử lý những bức ảnh lớn hơn .Net Framework cung cấp ra khỏi hộp, hãy kiểm tra các dự án FreeImage

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.Png; 
         break; 

        case ".bmp": 

         format = ImageFormat.Bmp; 
         break; 
       } 


       pictureBox.Image.Save(sv.FileName, format); 
      } 
+0

Thêm một số giải thích với câu trả lời cho cách câu trả lời này giúp OP trong việc khắc phục sự cố hiện tại –

Các vấn đề liên quan