Visual C# Developer Center > Visual C# Forums > Visual C# General > Picturebox image saving to a folder
Ask a questionAsk a question
 

AnswerPicturebox image saving to a folder

  • Saturday, November 07, 2009 1:24 PMLordSedna Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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

  • Saturday, November 07, 2009 1:31 PMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi,

    Could you try this code.

    pictureBox1.Image.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg);
    
    If it does not work could you please tell the value of _recPath variable while saving file.

    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

  • Saturday, November 07, 2009 1:31 PMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi,

    Could you try this code.

    pictureBox1.Image.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg);
    
    If it does not work could you please tell the value of _recPath variable while saving file.

    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
    •  
  • Saturday, November 07, 2009 2:51 PMLordSedna Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    pictureBox1.Image.Save(recPath + @"\" + count.ToString() + ".jpg", ImageFormat.Jpeg);
    thanks, this one worked just splendid!

    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
  • Saturday, November 07, 2009 3:06 PMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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);