我在下面的鏈接中遇到了這個問題 Converting String to Uint8List to use Image.memory(Uint8List uint8List)
不幸的是,我沒有得到有用的答案,所以我真的很想盡快解決這個問題。
總而言之,我的問題是我將影像資料作為字串“[255,216,255,225,1]”存盤在資料庫中,并以相同的格式檢索它。
問題是每當我嘗試將 t uint8List 轉換回 Image.memory(uint8List) 使用它時,我都會收到此錯誤。
E/FlutterJNI(23079): Failed to decode image
E/FlutterJNI(23079): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.
E/FlutterJNI(23079): at android.graphics.ImageDecoder.nCreate(Native Method)
E/FlutterJNI(23079): at android.graphics.ImageDecoder.access$200(ImageDecoder.java:169)
E/FlutterJNI(23079): at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:246)
E/FlutterJNI(23079): at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1754)
E/FlutterJNI(23079): at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1747)
E/FlutterJNI(23079): at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:524)
我很抱歉再次重新發布這個問題,但我真的非常渴望幫助,我不知道我做錯了什么。
任何幫助將不勝感激,在此先感謝。
uj5u.com熱心網友回復:
Uint8List _convertListToInt(String input) {
final reg = RegExp(r"([0-9] |\d )");
final pieces = reg.allMatches(input);
final result = pieces.map((e) => int.parse(e.group(0).toString())).toList();
List<int> example = result;
return Uint8List.fromList(example);
}
uj5u.com熱心網友回復:
Uint8List list;
Utf8Decoder( allowMalformed = true).convert(list);
嘗試這個 ; 希望這會奏效
uj5u.com熱心網友回復:
使用 'dart:convert' 和 'dart:typed_data' 包,然后使用 utf8.encode(String value),它將 String 轉換為 List,然后你可以使用:
String data="[1,2,3]";
List<int> list=utf8.encode(data);
Uint8List bytes = Uint8List.fromList(list);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/517372.html
上一篇:為什么我不能連續使用兩個索引?
