2012-12-08 5 views
0

제가 포토 박스에 화상 표시를 탐색하고자하는 화상은 C에있을 수 한 폴더에 저장한다 : 또는 D는 : 드라이브, 나 그림 상자에 표시하는 다음의 탐색에 대한 코딩을 이용폴더의 이미지를 탐색하고 저장하는 방법은 무엇입니까?

OpenFileDialog open = new OpenFileDialog(); 
     open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; 
     if (open.ShowDialog() == DialogResult.OK) 
     { 
      Image img = new Bitmap(open.FileName); 
      string imagename = open.SafeFileName; 
      Txt_countrylogo.Text = imagename; 
      pictureBox2.Image = img.GetThumbnailImage(340, 165, null, new IntPtr()); 
      open.RestoreDirectory = true; 
     } 

지금 나는 폴더에있는 심상을 저장하기를위한 도움이 필요하다, plz는 약간 아이디어를 건의한다.

답변

2

당신은 SaveFileDialog

var fd = new SaveFileDialog(); 
    fd.Filter = "Bmp(*.BMP;)|*.BMP;| Jpg(*Jpg)|*.jpg"; 
    fd.AddExtension = true; 
    if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
    { 
     switch (Path.GetExtension(fd.FileName).ToUpper()) 
     { 
      case ".BMP": 
       pictureBox2.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Bmp); 
       break; 
      case ".JPG": 
       pictureBox2.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Jpeg); 
       break; 
      case ".PNG": 
       pictureBox2.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Png); 
       break; 
      default: 
       break; 
     } 
} 
2

Image.Save 이미지 클래스의 메서드를 사용하여 이미지를 저장할 수 있습니다.

img.Save(@"d:\temp\" + imagename); 
+0

을,하지만 난이 오류를 얻고, 일반 오류가 발생했습니다 GDI +에서. – csura

+0

jpeg 확장을 사용했을 수 있으며 이미지의 형식이 다를 수 있습니다. 선택한 이미지의 확장명을 사용해야합니다. 올바른 확장자를 가져야하는 파일 이름을 사용하십시오. – Adil

0
OpenFileDialog open = new OpenFileDialog(); 
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; 
if (open.ShowDialog() == DialogResult.OK) 
{ 
    Image img = new Bitmap(open.FileName); 
    System.IO.File.Copy(open.FileName, open.FileName.Split('.')[0]+"_Copy."+open.FileName.Split('.')[1]); 
    //this is an example, you give it the name you want 
    string imagename = open.SafeFileName; 
    Txt_countrylogo.Text = imagename; 
    pictureBox2.Image = img.GetThumbnailImage(340, 165, null, new IntPtr()); 
    open.RestoreDirectory = true; 
} 
0

는이 코드를 사용할 수 있습니다 사용할 수 있습니다 :이 코드를 사용

Image bitmap = Image.FromFile("C:\\MyFile.bmp"); 
bitmap.Save("C:\\MyFile2.bmp"); 
관련 문제