Dart 将UINT8列表转换为颤振/省道ui中的图像

Dart 将UINT8列表转换为颤振/省道ui中的图像,dart,flutter,Dart,Flutter,我有这样一个场景,我必须从这样的图像中获取UInt8列表: List stuff = image.toByteData().buffer.asUInt8List() 做一些操作,然后回到一个 我尝试了以下方法: List stuff = image.toByteData().buffer.asUInt8List() ui.decodeImageFromList(stuff, (image){ // do stuff with image }); 但我一直得到这样一个例外: E/flutt

我有这样一个场景,我必须从这样的图像中获取UInt8列表:

List stuff = image.toByteData().buffer.asUInt8List()
做一些操作,然后回到一个

我尝试了以下方法:

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:
...

请注意,即使列表中没有任何更改,也会引发异常。如何使列表具有可编码格式?

ui。图像可以将自身转换为RGBA位图(或PNG),但无法将自身从位图转换回。(原因是没有任何方法可以告诉图像编解码器颜色深度、几何体等信息)解决方案是在位图前面添加一个BMP文件头,您可以在其中描述缺少的信息,然后将其传递给
实例化图像编解码器
。请参阅,但请注意,在这种情况下,所讨论的位图有一个奇怪的压缩颜色贴图。在32位RGBA的情况下,标题会更简单。

您可以使用MemoryImage类将UInt8列表转换为图像

var\u image=MemoryImage(图像)


您可以找到有关此类的更多详细信息

您可以使用下面给出的内存映像进行直接字节渲染

child: Image.memory(Uint8List bytes);
用这个

static Future<ui.Image> bytesToImage(Uint8List imgBytes) async{
    ui.Codec codec = await ui.instantiateImageCodec(imgBytes);
    ui.FrameInfo frame = await codec.getNextFrame();
    return frame.image;
  }
static Future bytesToImage(Uint8List imgBytes)异步{
ui.Codec Codec=wait ui.instantialeimagecodec(imgBytes);
ui.FrameInfo frame=wait codec.getNextFrame();
返回帧。图像;
}

在回答了这个问题后,我开始着手做一些事情,使之更容易。我正在将Uint8List转换为带有位图的图像,这是我制作的一个包。谢谢