saveAsJpeg static method
Save sourceFile
as JPEG to destinationFilePath
using given
quality
(1-100, null=100).
Image is scaled down to maximum size maxWidth
and maxHeight
.
If image is already smaller than maxWidth
and maxHeight
, the image is
scaled up to maximum size maxWidth
and maxHeight
only if canScaleUp
is true. Otherwise image is not resized.
maxWidth
and/or maxHeight
can be also null to not to resize image.
Resizing keeps aspect ratio.
If destinationFilePath
is null, a temporary file is created
automatically.
Returns saved JPEG image file.
Throws an exception on error.
Implementation
static Future<File> saveAsJpeg(
{required File sourceFile,
String? destinationFilePath,
int? quality,
int? maxWidth,
int? maxHeight,
bool canScaleUp = false}) async {
final params = _SaveAsJpegParameters(
sourceFile: sourceFile,
destinationFilePath: destinationFilePath,
quality: quality,
maxWidth: maxWidth,
maxHeight: maxHeight,
canScaleUp: canScaleUp);
final String? savedFile =
await _channel.invokeMethod('saveAsJpeg', params.toJson());
if (savedFile == null) {
throw Exception('Unknown error');
}
return File(savedFile);
}