Thursday, September 24, 2020

A generic error occurred in GDI+ while creating image from Base64 string

In a web service, while converting a Base64 string to file, it is sometimes giving error  - "A generic error occurred in GDI+ while creating image from Base64 string".

Solution:

I have used the below code and problem resolved.


[HttpPost]
public ActionResult UploadSignatureTwo(String imageString){     
    var bytes = Convert.FromBase64String(imageString);
    using (var imageFile = new FileStream(Path.Combine(path,"test.jpeg"), FileMode.Create))
    {
        imageFile.Write(bytes, 0, bytes.Length);
        imageFile.Flush();
    }
}

No comments: