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