0

i want to browse the image and display in picture box and the image should save in one folder, which may be in C: or D: drive, i used the following coding for browse and displaying in picture box

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; } 

now i need the help for saving the image in folder, plz suggest some idea.

4 Answers 4

3

You can use the 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; } } 
Sign up to request clarification or add additional context in comments.

Comments

2

You can use Image.Save method of Image class to save the image.

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

2 Comments

i used this code, but i am getting this error, A generic error occurred in GDI+.
You might have used jpeg extension and the image would be of different format, you have to use the extension you have for selected image. Use file name you have to get the right extension.
1
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; } 

Comments

0

you can use this code :

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.