compress method
Compresses image data in memory.
Takes raw image data as Uint8List and applies compression according to options.
Returns compressed image data as Uint8List.
Throws ImageCompressException if compression fails.
Implementation
@override
Future<Uint8List> compress(Uint8List data, CompressOptions options) async {
try {
final result = await methodChannel.invokeMethod<Uint8List>('compress', {
'data': data,
'maxWidth': options.maxWidth,
'maxHeight': options.maxHeight,
'quality': options.quality,
});
if (result == null) {
debugPrint(
'Platform returned null result for compress, returning original data',
);
return data;
}
return result;
} on PlatformException catch (e) {
debugPrint(
'Platform exception during compress: ${e.message} (${e.code})',
);
return data;
} catch (e) {
debugPrint('Unexpected error during compress: $e');
return data;
}
}