processWithImageToByteData method

  1. @override
Future<ByteData?> processWithImageToByteData(
  1. Uint8List imageData,
  2. int width,
  3. int height
)
override

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) {
            print('processWithImageToByteData - Received null result');
            return null;
        }

        final List<int> resultList = result as List<int>;
        // print('processWithImageToByteData - Result data size: ${resultList.length}');

        if (resultList.isEmpty) {
            print('processWithImageToByteData - Received empty result');
            return null;
        }

        // 确保返回的数据大小与输入图像大小匹配
        final expectedSize = width * height * 4; // RGBA format
        if (resultList.length != expectedSize) {
            print('processWithImageToByteData - Invalid data size. Expected: $expectedSize, Got: ${resultList.length}');
            return null;
        }

        final byteData = ByteData.view(Uint8List.fromList(resultList).buffer);
        // print('processWithImageToByteData - Successfully created ByteData');
        return byteData;
    } catch (e) {
        print('Error in processWithImageToByteData: $e');
        return null;
    }
}