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) {
throw ImageCompressException(
'Platform returned null result',
'COMPRESSION_FAILED',
);
}
return result;
} on PlatformException catch (e) {
throw ImageCompressException(
e.message ?? 'Image compression failed',
e.code,
);
} catch (e) {
throw ImageCompressException(
'Unexpected error during compression: $e',
'COMPRESSION_FAILED',
);
}
}