图像不是通过使用JSON格式的asp.net WebAPI重现的Byte []数组重建

时间:2018-05-09 18:09:44

标签: c# json.net

这是ImageBytes生成的方式

Stream stream = postedFile.InputStream;
BinaryReader binaryReader = new BinaryReader(stream);
imgBytes = binaryReader.ReadBytes((int)stream.Length);

解释:这些imgBytes然后使用webAPI 2 POST到DB,当这些字节使用JSON格式的GET方法从DB检索,然后转换为Base64String但不生成图像

以JSON格式使用GET方法重播

var jsonString = response.Content.ReadAsStringAsync().Result;
byte[] mapbytes = System.Text.Encoding.UTF8.GetBytes(jsonString);
String base64String = Convert.ToBase64String(mapbytes);
String src = "data:image/png;base64," + base64String;

注意 已经在stackoverflow上尝试了所有发布的答案,但没有得到解决方案 也可以使用

JSON转换为字节[]

byte [] mapbytes = Encoding.ASCII.GetBytes(response.Content.ReadAsStringAsync()。Result);

0 个答案:

没有答案