我收到一個 PNG 影像(不是 URI)作為對我的 api 請求的回應,如下所示:
Future PostToGetPostImages(String pic_id,String pic_type) async {
try {
var parms = {
'code': pic_type "_" pic_id,
};
Response response = await _dio.post(_get_post_image,
data: parms,
options: Options(contentType: Headers.formUrlEncodedContentType),
onSendProgress: (int sent, int total) {
print('sent : $sent // total : $total');
}, onReceiveProgress: (v, s) {
print('v : $v // s : $s');
});
print('***** Response body Download Profile Images: ${response.data} **********');
return response.data;
} catch (error, stacktrace) {
_handleError(error);
print("Exception occured A: $error stackTrace: $stacktrace");
}
}
這是執行后列印的內容:
I/flutter (12777): ***** Response body Download Profile Images: ?PNG
我需要知道如何在顫振中顯示此回應(png 影像),我正在使用此代碼,但它不起作用:
FutureBuilder(
future: aptProvider().PostToGetProfileImages("1", "m"),
builder: (context, snapshot) {
return CircleAvatar(
radius: 65.0,
backgroundImage: backgroundImage: NetworkImage(snapshot.data
.toString()));
}),
uj5u.com熱心網友回復:
也許 png 就像一個像 404 這樣的虛擬影像,就像附加影像中的影像一樣,所以你必須復制并嘗試使用 Image.network 檢查它,如果一切正常,你繼續使用 image.network
uj5u.com熱心網友回復:
這里的問題是您沒有使用 URL 影像,請確認使用以(.png、jpg、.. 等)結尾的 URL,并通過在瀏覽器中打開它來確認。
然后
要在您的小部件中顯示它,請使用以下方式之一
第一的
Image.network('URL')
// ex: Image.network('https://picsum.photos/250?image=9')
第二
Container( height : 100 , width :100 , decoration : Box decoration (
image : Decoration image ( Network image ('URL'), ),
), ), ),
uj5u.com熱心網友回復:
看起來您將影像作為位元組陣列,base64 字串。
這是我解決這個問題的方法。
var base64 = response.split(';base64,')[1];
base64 = base64.replaceFirst('binary data/', '');
Uint8List bytes = base64Decode(base64);
// Image Widget which you can put in anywhere.
Image.memory(bytes, fit: BoxFit.contain)
uj5u.com熱心網友回復:
如果您從回應中獲取影像 url,則可以使用 Image.network(imageUrl)
或者
如果您以 Uint8List 的形式獲取 imageData,則可以使用 Image.memory(imageData)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/354038.html
下一篇:影像高度沒有變化
