Invalid length for a Base-64 char array during decoding/decryption

前端 未结 2 621
不思量自难忘°
不思量自难忘° 2020-12-06 16:59

Q: I face the following big problem :

from time to another i find the following exception:

Invalid length for a Base-64 char array

<

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 17:30

    string imag = img;
    imag = imag.Replace("\", "");
    int c = imag.Length % 4;
    if ((c) != 0)
        imag = imag.PadRight((imag.Length + (4 - c)), "=");
    [] converted = Convert.FromBase64String(imag);
    using (System.IO.MemoryStream vstream = new System.IO.MemoryStream(converted)) {
        return Image.FromStream(vstream);
    }
    

提交回复
热议问题