compressImageBytes method
Future<ImageBytesResult>
compressImageBytes(
- Uint8List source,
- ImageCompressConfig config
override
Compress bytes in memory. Images only — a video would mean copying tens of megabytes across the platform channel in one message.
Implementation
@override
Future<ImageBytesResult> compressImageBytes(
Uint8List source,
ImageCompressConfig config,
) async {
await _ensureImageLoaded();
try {
final cfg = config.toMap().jsify()! as JSObject;
final res = await _jsCompressImageBytes(source.toJS, cfg).toDart;
return ImageBytesResult(
bytes: res.bytes.toDart,
originalSizeBytes: res.originalSizeBytes,
width: res.width,
height: res.height,
format: res.format,
skipped: res.skipped,
);
} catch (e) {
throw ImageCompressException(
CompressErrorCode.imageCompressFailed, e.toString());
}
}