在GDI+中从Base64字符串创建图像时发生了一个通用错误

本文关键字:一个 错误 发生了 Base64 中从 GDI+ 字符串 创建 图像 | 更新日期: 2023-09-27 18:04:52

这是我的动作方法在asp.net mvc项目-

[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.
}

imageString:

示例内容
  /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wB .....

为什么我得到那个异常- A generic error occurred in GDI+

在GDI+中从Base64字符串创建图像时发生了一个通用错误

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();
}
相关文章: