1

下面是我的原始代码在颤振版本 1.22.6 下运行良好,但是当我升级到颤振版本 2.2.1 时出现“无法将参数类型'List'分配给参数类型'Uint8List'”的错误。标记为红色错误:

最终油漆 = 等待 PaintingBinding.instance!.instantiateImageCodec(asset != null ? img.encodePng(asset) : buffer);

任何人都可以提供帮助将不胜感激。

这是我的代码:

Future<BeautifulPopup> recolor(Color color) async {
primaryColor = color;
final illustrationData = await rootBundle.load(instance.illustrationKey);
final buffer = illustrationData.buffer.asUint8List();
img.Image asset;
asset = img.readPng(buffer)!;

img.adjustColor(
  asset,
  saturation: 0,
  // hue: 0,
);
img.colorOffset(
  asset,
  red: primaryColor.red,
  // I don't know why the effect is nicer with the number ╮(╯▽╰)╭
  green: primaryColor.green ~/ 3,
  blue: primaryColor.blue ~/ 2,
  alpha: 0,
);

final paint = await PaintingBinding.instance!
    .instantiateImageCodec(asset != null ? img.encodePng(asset) : buffer);
final nextFrame = await paint.getNextFrame();
_illustration = nextFrame.image;
return this;

}

...

4

1 回答 1

0

这是因为它们是不同的类型。但这里有一种处理转换的简单方法:

Uint8List uint8List;
List<int> list;  

// convert List<int> to Uint8List. 
uint8List = Uint8List.fromList(list);  

// convert Uint8List to List<int>
list = List<int>.from(uint8List);

干杯!

大卫

于 2021-07-08T18:34:26.977 回答