locked
Trying to save a pictureBox image to a file, sometimes getting an exception thrown. RRS feed

  • Question

  • I'm trying to save a pictureBox image out to a file and sometimes am getting an exception thrown.

    If I do this:

    pictureBox1.Image.Save("image", System.Drawing.Imaging.ImageFormat.Bmp);

    it works just fine.

    If I do this:

    pictureBox1.Image.Save("C:image", System.Drawing.Imaging.ImageFormat.Bmp);

    it also works fine.

    But if I try to specify a particular subdirectory, like this:

    pictureBox1.Image.Save("C:\Pictures\image", System.Drawing.Imaging.ImageFormat.Bmp);

    it fails, throwing a generic exception.

    Even if I just put a slash after the C:, like this

    pictureBox1.Image.Save("C:\image", System.Drawing.Imaging.ImageFormat.Bmp);

    it throws a generic exception.

    What am I doing wrong?

    Wednesday, November 25, 2020 1:10 AM

All replies

  • The first case will save the image in current folder of the program, maybe you have access to that folder?

    The second case will save the image to "current folder of C drive", maybe you also have access to that folder?

    The third and forth cases will save the image to specific path you provided. If you don't have access to these folder, or if these folder does not exist, it will throw exception.

    Wednesday, November 25, 2020 2:10 AM
    Answerer
  • [...]

    But if I try to specify a particular subdirectory, like this:

    pictureBox1.Image.Save("C:\Pictures\image", System.Drawing.Imaging.ImageFormat.Bmp);

    it fails, throwing a generic exception.

    [...]


    Did you really write "C:\Pictures\image" instead of @"C:\Pictures\image" or "C:\\Pictures\\image"?


    Wednesday, November 25, 2020 9:31 AM