processWithImageToByteData method
Implementation
@override
Future<ByteData?> processWithImageToByteData(Uint8List imageData, int width, int height) async {
try {
final result = await methodChannel.invokeMethod('processWithImageToByteData', {
'imageData': imageData,
'width': width,
'height': height,
});
if (result == null) {
return null;
}
final List<int> resultList = result as List<int>;
if (resultList.isEmpty) {
return null;
}
final expectedSize = width * height * 4; // RGBA format
if (resultList.length != expectedSize) {
return null;
}
// 直接使用 resultList 创建 ByteData,避免创建额外的 Uint8List
return ByteData.view(Uint8List.fromList(resultList).buffer);
} catch (e) {
print('Error in processWithImageToByteData: $e');
return null;
}
}