文件二进制数据,List转Uint8List

2021-12-29  本文已影响0人  晓函

在flutter,有的获取二进制数据是List<int>,有的是Uint8List,相当于C语言里面
char和byte,int和uint的区别,也是可以互相转换的。

List<int> imgBytes = xxxx;
Uint8List bytes = Uint8List.fromList(imgBytes);

举例:
比如Image类和File类

File file('/User/123.jpg');
Uint8List fileBytes = await file.readAsBytes();
Image img = decodeImage(fileBytes);
List<int> imgBytes = encodePng(img);

进入主题,List<int>转Uint8List

Uint8List bytes = Uint8List.fromList(imgBytes);
上一篇下一篇

猜你喜欢

热点阅读