Visual C# Developer Center >
Visual C# Forums
>
Visual C# General
>
Picturebox image saving to a folder
Picturebox image saving to a folder
- Hello mates,
i have variable called _recPath which contains a string for files to be saved to. This is stored on a variable because user specifies the destination. The problem is, there is a pictureBox, and when a method is being called, this pictureBox's Image is supposed to be saved to the target path. I used the following code, but it keeps saving the files to the desktop, not in any folder..
pictureBox1.Image.Save(@"" + _recPath + "" + count.ToString() + ".jpg", ImageFormat.Jpeg);
count is a variable goes like count++; it is used for file name. so _recPath is actually path, count is the file name..
what else i can use for it?
Thanks
Blitzkrieg- Edited byLordSedna Saturday, November 07, 2009 1:26 PMmissing info
Answers
- Hi,
Could you try this code.
If it does not work could you please tell the value of _recPath variable while saving file.pictureBox1.Image.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg);
You can also allow user to select folder with the following code. Could you try this too.
PictureBox pictureBox1 = new PictureBox(); using (FolderBrowserDialog fbd = new FolderBrowserDialog()) { fbd.ShowDialog(); string recpath = fbd.SelectedPath; pictureBox1.Image.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg); }- Marked As Answer byLordSedna Saturday, November 07, 2009 3:08 PM
All Replies
- Hi,
Could you try this code.
If it does not work could you please tell the value of _recPath variable while saving file.pictureBox1.Image.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg);
You can also allow user to select folder with the following code. Could you try this too.
PictureBox pictureBox1 = new PictureBox(); using (FolderBrowserDialog fbd = new FolderBrowserDialog()) { fbd.ShowDialog(); string recpath = fbd.SelectedPath; pictureBox1.Image.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg); }- Marked As Answer byLordSedna Saturday, November 07, 2009 3:08 PM
thanks, this one worked just splendid!pictureBox1.Image.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg);
Now another question :) the saved images are in low res, and not so high quality, but i want to decrease images' quality even more.. is there a way to do it before or while saving the image? the point is, i want to reduce the file size..
Blitzkrieg- Hi,
You can use GetThumbnailImage method to get smaller images.
Here is a sample.
Image i=pictureBox1.Image.GetThumbnailImage(pictureBox1.Image.Width / 2, pictureBox1.Image.Height / 2, null, IntPtr.Zero) i.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg);


