我有这样一个场景,我必须从这样的图像中获取UInt8List:
List stuff = image.toByteData().buffer.asUInt8List()执行一些操作,然后返回到Image。
我尝试过以下几种方法:
List stuff = image.toByteData().buffer.asUInt8List()
ui.decodeImageFromList(stuff, (image){
// do stuff with image
});但我一直收到这样的异常:
E/flutter (10201): [ERROR:flutter/lib/ui/painting/codec.cc(97)] Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
E/flutter (10201): [ERROR:flutter/shell/common/shell.cc(186)] Dart Error: Unhandled exception:
...请注意,即使列表中没有任何更改,也会抛出异常。如何才能使列表具有可编码的格式?
发布于 2019-01-04 06:42:37
ui.Image可以将自身转换为RGBA位图(或PNG),但不能将自身从位图转换回来。(原因是没有任何方法可以告诉图像编解码器内容,如颜色深度、几何形状等。)解决方案是在位图的前面添加一个BMP文件头,您可以在其中描述缺少的内容,然后将其传递给instantiateImageCodec。请参阅this answer,但请注意,在这种情况下,有问题的位图有一个奇怪的压缩颜色贴图。在32位RGBA的情况下,报头会更简单。
发布于 2020-08-09 03:07:20
对于直接的字节渲染,您可以使用如下所示的内存图像
child: Image.memory(Uint8List bytes);发布于 2020-05-02 18:45:57
https://stackoverflow.com/questions/54030340
复制相似问题