首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将颤振字符串转换为Uint8List以使用Image.memory

将颤振字符串转换为Uint8List以使用Image.memory
EN

Stack Overflow用户
提问于 2022-10-18 11:13:44
回答 3查看 81关注 0票数 0

我在Converting String to Uint8List to use Image.memory(Uint8List uint8List)下面的链接中有这个问题

不幸的是,我没有得到有帮助的答案,所以我非常渴望尽快解决这个问题。

总之,我的问题是,我要将图像数据以字符串"255,216,255,225,1“的形式存储在数据库中,并以相同的格式检索它。

问题是,每当我试图将t uint8List转换回Image.memory(uint8List)使用它时,我就会得到这个错误。

代码语言:javascript
运行
复制
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)

我很抱歉重新发布了这个问题,但我真的非常渴望帮助,我不知道我做错了什么。

如有任何帮助,我们将不胜感激。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-10-18 11:32:49

代码语言:javascript
运行
复制
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);
  }
票数 0
EN

Stack Overflow用户

发布于 2022-10-18 11:21:50

代码语言:javascript
运行
复制
Uint8List list;
Utf8Decoder( allowMalformed = true).convert(list);

试试这个;希望这个能成功。

票数 0
EN

Stack Overflow用户

发布于 2022-10-18 11:42:02

使用‘dart:转换’和'dart:typed_data‘包,然后使用utf8.encode(String值),它将字符串转换为List,然后您可以使用:

代码语言:javascript
运行
复制
String data="[1,2,3]";
List<int> list=utf8.encode(data);
Uint8List bytes = Uint8List.fromList(list);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74110027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档