我正在开发Flutter应用,其中我需要显示图像形式的字节。
这是我得到的JSON响应。
{
"result": {
"reF_ID": 140,
"filE_BYTES": "iVBORw0KGgoAAAANSUhEUgAAAWsAAACLCAMAAACQq0h8AAAAkFBMVEX39/f7+/v8/PwAAAD19fXw8PDx8fHq6uro6OhdWlvj4+M0MDHLysoHAADFxMRJRke/vr5ST1Csq6vb29tjYGFDQEGHhYaAfn89OjsiHh/T0tJYVVYuKiukoqPe3d1saWobFRcUDQ+Yl5e1tLSQjo44NDWhn6AfGxx3dXYnIySUk5N4dnZvbW6DgYEMAAWrqappj+/tAAAObElEQVR4nO1dZ4OiOhTlJiBdivQiBFBEEf//v3uJZcq+KSA7uztOzredFcTD5eS2XASBg4ODg4ODg4ODg4ODg4ODg4ODg4ODg+M+wP/wt6/oAQGAEBIkZb1KlnW+b4LwcAiDqk5k9Lcv7YHAWBYkOamrsLA2MSFlm0WWo3qe6kQtsWpu2r8FgECUDbcpIkLiSA33eb1MNEkUxcv/i1Idd2tO9lwwnhM3UDNC/KJxDU2WmI68lmhkt7rGuZ4DSqhk5MWmbK2+MjRK8turIFp2eM+pvhtUn6XE7aOhSwN7JTFLfvejy2zwFn/y4h4J1ICVZWgREoX2WvjEpUOGbqoKN+t7AEhc50WL9V29+sicr0BJZnoyp3o6AAlJrhJiNbYkoBEMQuKbBad6Mqh0JNu0HNIqkcbwTIFWFuZWPRWU6FWeEqJuV+JIoulBa8tMOdXTAEipi860KNETkhugpdjhjvUUAFoYB92MmmQK0fQ4WcUOjxcnAIR15eDssFyMlo7rgZRqn1M9GtTvsA8tdk6aMJU0kAocrXh+byQA1rmP9SAZvxo+H8upngAkGGGG05M2nWhGdY83Cad6DABJtkfig7G4q6gC0s7cGJzqEQDQtj72q/U9Js2OF3usj7ZqAPHHrqBUpgPdTF353johLEIzG23VSGtU42eSDWAcSlIshbsrsiDucLYcSTVArWO8+4lcg7AshjhMJrt4L06xoFSPtWpYNFSrIu/ub/u2QMLSw1mzmtNkAIsD1kdT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KQBxrNvDG9Aeo23ifSy1c7nv/O2F0lhl2724YSvOkipzjuT9SHu2Yt5lzi1wG07BePj16svGycGHvGiycdYMki8vkFk7dG+YFkrN+c3sCmMrS+twuafdU0QRAe+sJTHSvSs/j8/kFv17CIT5OFv+ddjIeUDs+dBeyxXNc7n6pH+aqQzfIhJJzVUPkh3qMJFNfz9S7uMj3yLSdVVY9q8SGoWPZtrSwE+FeWvTFA7hAl12wW9UMbp43TNCbWy57gq3x8Xdj8PujNX8iapimSJKKX+EYUv0AVt4e8rk/7Q9qV0a5e5RvSv1gBzwk9/TfIx734nrS+CVhVada2ne81dSIiMRzil+UR5n2wlMZfvMIHAkusybK0oOvLOf3hvCiJg3TKXjd+cPwegJB3+Pg8J+Q8S0u/Dkjg+J0AZYd199mG0TokJZePrwDbkag+6wf1PnQuH18CALczj0/5f2B7yadtH+cYCZCpftjPEfnqgMvjrAlPHO8AJSl+3hMN0jajMTqXjy/AeYbb057oy3yVaRv1OUYCFo2pP1W10OrAxjNx+fgKIK143oWIzpUXLh9fAzCiJ/+DjVzG/qz5khzvgoaKcefeJqqw6W77x96A9fcAi+CpmwnJzai+D467AGsV75TrPMh682ErNccsICMa9pe50ijxcFbx4OWrAG6cXXYxIy1oyeHeN4pyfAY2UuEy/ApJJ312iZzjfbAEyPnVLoCWKQ0TeZbpy4DWzvkdIgCrnXl5WwPH1wASn2zZ23SUqmPNCNyovwzI1onL2u1qnwv11wJqErNcNRXqeS984PgMcGrjGkHSm3r+5zdf/Sgg9m4olBzKuJn3SmKOzwA5acu+KOPjjNcCcowBquM2bs3ywJNMXw1IsrIkWciZ/npAiFurmvOqS46xgOS0XHCb/jMAbtIcHBwcHBwcHBwcM/AfXD31pNdUaG4AAAAASUVORK5CYII="
},
"targetUrl": null,
"success": true,
"error": null,
"unAuthorizedRequest": false,
"__abp": true
}
这是应用程序辅助代码,
Future<String> getPanPhoto() async {
var res = await http.get(
Uri.encodeFull(getPanPhotoUrl),
headers: {
"Content-type": "application/json",
"Accept": "application/json"
},
);
var photoResponse = json.decode(res.body);
Map<String, dynamic> result = photoResponse['result'];
String success = photoResponse['success'].toString();
if (success == "true") {
String refId = result['reF_ID'].toString();
var imageResponse = result['filE_BYTES'];
_base64 = BASE64.encode(imageResponse.toString());
Uint8List bytes = BASE64.decode(imageResponse.bodybytes);
}
setState(() {
_photoFile = bytes as File;
});
print(res.statusCode);
print(res.body);
}
我要在其中显示图片
return Container(
margin: const EdgeInsets.only(
top: 10.0,
bottom: 10.0,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.memory(bytes),
),
);
在打电话时,我出现了错误,
发生异常。 NoSuchMethodError(NoSuchMethodError:方法'encode'在null上被调用。接收方:null尝试调用:encode('')
答案 0 :(得分:3)
将字节转换为图像很简单,只需一行代码:
Image.memory(base64Decode(“放入您的基本64字符串”));
答案 1 :(得分:2)
您可以将字节转换为抖动图像。
这是秘密的方法:
Image.memory(base64Decode("base64 string"));