1、引用yuv_converter库
yuv_converter: ^0.0.1
2、导入头文件:
import 'package:yuv_converter/yuv_converter.dart';
3、yuv转rgb
YuvConverter.yuv420NV21ToRgba8888(yuvRawData, 512, 512)
根据yuv格式选择不同的api。
举个例子:
void initState() {
super.initState() ;
loadAssetAsUint8List("assets/yuv/1_uyvy.yuv").then((yuvRawData){
rgbga1 = YuvConverter.yuv422uyvyToRgba8888(yuvRawData, 512, 512) ;
setState(() {
});
}) ;
loadAssetAsUint8List("assets/yuv/1_nv21.yuv").then((yuvRawData){
rgbga2 = YuvConverter.yuv420NV21ToRgba8888(yuvRawData, 512, 512) ;
setState(() {
});
}) ;
}
Future<Uint8List> loadAssetAsUint8List(String assetPath) async {
// 使用rootBundle加载assets中的文件
final ByteData data = await rootBundle.load(assetPath);
// 将ByteData转换为Uint8List
final Uint8List uint8List = data.buffer.asUint8List();
return uint8List;
}
github: