简体   繁体   中英

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

Here is my action method in asp.net mvc project-

[HttpPost]
public ActionResult UploadSignatureTwo(String imageString)
{      
    byte[] bytes = Convert.FromBase64String(imageString);

    Image img;
    using (MemoryStream ms = new MemoryStream(bytes))
    {
       img = Image.FromStream(ms);
    }
    img.Save(path,ImageFormat.Jpeg); //in app_data folder, has write permission.
}

Sample content of imageString:

  /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wB .....

Why I'm getting that exception - A generic error occurred in GDI+ ?

var bytes = Convert.FromBase64String(image);
using (var imageFile = new FileStream(Path.Combine(path,"test.jpeg"), FileMode.Create))
{
    imageFile.Write(bytes, 0, bytes.Length);
    imageFile.Flush();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM