C# 未通过使用JSON格式的asp.net WebAPI检索的字节[]数组重建图像

C# 未通过使用JSON格式的asp.net WebAPI检索的字节[]数组重建图像,c#,json.net,C#,Json.net,这就是ImageBytes的生成方式 Stream stream = postedFile.InputStream; BinaryReader binaryReader = new BinaryReader(stream); imgBytes = binaryReader.ReadBytes((int)stream.Length); 解释:这些imgBytes然后使用webAPI 2发布到DB,当这些字节使用JSON格式的GET方法从DB检索时,然后转换为Base64String,但不会生成图

这就是ImageBytes的生成方式

Stream stream = postedFile.InputStream;
BinaryReader binaryReader = new BinaryReader(stream);
imgBytes = binaryReader.ReadBytes((int)stream.Length);
解释:这些imgBytes然后使用webAPI 2发布到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上尝试所有已发布的答案,但未获得解决方案 还可以使用


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

你说它没有生成是什么意思?你有例外吗?什么都没发生吗?如果你得到一个异常,它是什么,是哪一行抛出的?@itsme86不,我没有得到任何异常,什么都没有发生,也没有生成,这意味着当我转换Bytes=>base64String并将其用作图像时,源图像没有重建(生成)
jsonString
的确切值是多少?它是否具有
{“key”:“value”}
格式?或者它仅仅是密钥的值?也是
postedFile.InputStream
使用的
Encoding
?如果您愿意,为了社区的利益。例如,如果你认为将来可能会有其他人遇到这样的事情。