1

I have method like this,

public static void Base64ToImageAndSave(string rawData, string path)
        {
            string parsedData;

            parsedData = rawData.Contains(',')
                ? rawData.Substring(rawData.IndexOf(',') + 1)
                : rawData;

            byte[] imageBytes = Convert.FromBase64String(parsedData);

            using (MemoryStream memoryStream = new MemoryStream(imageBytes))
            {
                using (Image image = Image.FromStream(memoryStream))
                {
                    image.Save(path, ImageFormat.Jpeg);
                }
            }

        }

I send base64 parameter for save the picture as a jpeg file. But I have this error

A generic error occurred in GDI+

on this line,

image.Save(path, ImageFormat.Jpeg);

I use using for dispose, but still have error. How can i solve this problem? thanks.

aynakolik
  • 89
  • 1
  • 1
  • 9

1 Answers1

3

For future reference:

If you are getting the same error , then we can say that you don't have a write permission on some directory.

For example, if you are trying to save the Image from the memory stream to the file system , you may get that error. Make sure to add write permission in folder or for the network service account.

Hope this helps!

jomsk1e
  • 3,585
  • 7
  • 34
  • 59