7

I have got a bitmap i would like to save to disk, however i have only managed to save it in same directory as the program exe.

This is the only way i got it to work:

image.save("img.jpg", ImageFormat.Jpeg);

I would like to save it somewhere else on the disk regardless of where the program exe is. none of these works, i get: A generic error occurred in GDI+.

image.save("C:\\img.jpg", ImageFormat.Jpeg);
image.save(@"C:\\img.jpg", ImageFormat.Jpeg);

EDIT: btw is it possible to make folders too? something like this? (i get the same error as always..)

image.save("foldername/img.jpg", ImageFormat.Jpeg);

EDIT2: got it to save to a folder only if the folder allready exists. Could there be a permission thing? anything that needs to be imported?

user2725580
  • 1,293
  • 2
  • 17
  • 21

4 Answers4

6

Try this:

image.save("C:/img.jpg", ImageFormat.Jpeg);
E.Vaughan
  • 293
  • 2
  • 13
  • Hopefully these can help: http://www.codeproject.com/Questions/283361/A-generic-error-occurred-in-GDIplus, http://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream – E.Vaughan Nov 11 '13 at 14:48
4

According to URL pattern definition, you should use '/' insted of '\' in resource location path, so:

image.save(@"C:/img.jpg", ImageFormat.Jpeg);
Dzmitry Martavoi
  • 6,867
  • 6
  • 38
  • 59
2

I had the same issue. The quick workaround was to manually create the directory and it worked like a champ:

string directory_where_you_want_to_save_file = "./subdir";
System.IO.Directory.CreateDirectory(pathString);
0

try this: image.Save(Application.StartupPath + "\img.jpg");

Nofar Eliasi
  • 109
  • 5