commit
43d2003e6c
|
|
@ -69,6 +69,10 @@ class ImageConverter {
|
|||
ResizeMode resizeMode = const OriginalResizeMode(),
|
||||
bool runInIsolate = true,
|
||||
}) async {
|
||||
assert(
|
||||
quality >= 1 && quality <= 100,
|
||||
'Quality must be between 1 and 100.',
|
||||
);
|
||||
if (runInIsolate) {
|
||||
return await compute(_convertInIsolate, (
|
||||
inputData: inputData,
|
||||
|
|
|
|||
|
|
@ -228,10 +228,9 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
|
|||
}
|
||||
|
||||
CGImageRef _resizeImage(CGImageRef originalImage, int width, int height) {
|
||||
CGColorSpaceRef? colorSpace;
|
||||
CGContextRef? context;
|
||||
try {
|
||||
colorSpace = CGImageGetColorSpace(originalImage);
|
||||
final colorSpace = CGImageGetColorSpace(originalImage);
|
||||
if (colorSpace == nullptr) {
|
||||
throw Exception('Failed to get color space from image.');
|
||||
}
|
||||
|
|
@ -271,7 +270,6 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
|
|||
}
|
||||
return resizedImage;
|
||||
} finally {
|
||||
if (colorSpace != null) CFRelease(colorSpace.cast());
|
||||
if (context != null) CFRelease(context.cast());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,17 +44,17 @@ final class ImageConverterWeb implements ImageConverterPlatform {
|
|||
ResizeMode resizeMode = const OriginalResizeMode(),
|
||||
}) async {
|
||||
final img = HTMLImageElement();
|
||||
final decodeCompeleter = Completer<void>();
|
||||
final decodeCompleter = Completer<void>();
|
||||
|
||||
final blob = Blob([inputData.toJS].toJS);
|
||||
final url = URL.createObjectURL(blob);
|
||||
img.onLoad.listen((_) => decodeCompeleter.complete());
|
||||
img.onLoad.listen((_) => decodeCompleter.complete());
|
||||
img.onError.listen((e) {
|
||||
URL.revokeObjectURL(url);
|
||||
decodeCompeleter.completeError('Failed to load image: $e');
|
||||
decodeCompleter.completeError('Failed to load image: $e');
|
||||
});
|
||||
img.src = url;
|
||||
await decodeCompeleter.future;
|
||||
await decodeCompleter.future;
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
final canvas = HTMLCanvasElement();
|
||||
|
|
|
|||
Loading…
Reference in New Issue