Error“ Parameter is not valid ” while converting Bytes into Image

前端 未结 6 898
心在旅途
心在旅途 2020-11-30 12:19

I am converting bytes into an image but I get an error

Parameter is not valid

I am pasting my code. Kindly check the code and

6条回答
  •  鱼传尺愫
    2020-11-30 13:02

    In my case I got the error since my base64 string had wrong encoding before calling Image.FromStream. This worked for me in the end:

    byte[] bytes = System.Convert.FromBase64String(base64ImageString);
    
    using (MemoryStream ms = new MemoryStream(bytes))
    {
        var image = Image.FromStream(ms);
        image.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
    }
    

提交回复
热议问题