我需要做类似的事情adapter。我收到ui.Image作为in参数,我应该发送到outUint8List。现在我发现如何ui.Image转换为png数据,但它占用了非常大的内存大小。
例如,如果我在磁盘上获取 2,6 MB 文件,将其读取为
ui.Image,然后尝试将其转换回数据,toByteData(.png)结果我在磁盘上有 11.45 MB。
我的代码
/// Encode each page from [ui.Image] to data [Uint8List].
///
/// throw [ImageEncodeException] when one of [pages] can't encode.
@visibleForTesting
Future<List<Uint8List>> encodePages(List<ui.Image> pages) {
return Future.wait(pages.map((ui.Image page) async {
final ByteData? byte =
await page.toByteData(format: ui.ImageByteFormat.png);
if (byte == null) {
throw const ImageEncodeException();
}
return byte.buffer.asUint8List();
}));
}
在 emumImageByteFormat我只看到rawRgba,rawUnmodified和png. 那么我如何转换ui.Image为 jpeg 数据呢?有什么建议么?