2010-02-18 44 views
15

Come possiamo salvare i file di immagine (tipi come jpg o png) in C#?salva i file di immagine in C#

+4

Questa domanda è molto vago, puoi fornire maggiori dettagli su ciò che stai cercando di realizzare? –

+3

Voleva sapere come salvare un'immagine, questo è quello che ha ottenuto. –

+4

ciao, è vero, i miei mezzi erano ciò che hai detto. ma io sono lei :) –

risposta

22

in C# ci Metodo Image.Save con questi parametri (string filename, FormatoImmagine)

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

È che tutto il necessario?

// 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"); 

Si dovrebbe essere in grado di utilizzare il Save Method dal Image Class ed essere più che bene come illustrato sopra. Il metodo di salvataggio ha 5 opzioni differenti o sovraccarichi ...

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

Se avete bisogno di più ampia gestione delle immagini di .Net Framework fornisce fuori dalla scatola, controllare il FreeImage progetto

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

Aggiungi qualche spiegazione con la risposta per come questa risposta aiuta l'OP nel risolvere il problema attuale –