Problem with Image.Save

Jul 4, 2007 at 10:13 PM
Edited Jul 4, 2007 at 10:14 PM

I am trying to save the pictures of a list of Facebook contacts as follows:

Collection<Facebook.User> friends = facebookService1.GetFriends();
foreach (Facebook.User friend in friends)
friend.Picture.Save("C:\\" + friend.Name + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

If the user DOES NOT have a picture it works (it writes on this the "question mark" default picture), but if the user does have a picture it fails with the following exception:

System.Runtime.InteropServices.ExternalException was unhandled
Message="A generic error occurred in GDI+."

Has anybody suffered this problem before? Did you find a solution?

Thank you!
Jul 4, 2007 at 10:19 PM
After some tinkering I found the following solution:

Image image = new Bitmap(friend.Picture);
image.Save("C:\\" + friend.Name + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

If anybody has a better suggestion I'd be happy to hear. Thanks!