compressWithFile static method

Future<Uint8List?> compressWithFile(
  1. String path, {
  2. int minWidth = 1920,
  3. int minHeight = 1080,
  4. int inSampleSize = 1,
  5. int quality = 95,
  6. int rotate = 0,
  7. bool autoCorrectionAngle = true,
  8. CompressFormat format = CompressFormat.jpeg,
  9. bool keepExif = false,
  10. int numberOfRetries = 5,
})

Compress file of path to Uint8List.

Implementation

static Future<Uint8List?> compressWithFile(
  String path, {
  int minWidth = 1920,
  int minHeight = 1080,
  int inSampleSize = 1,
  int quality = 95,
  int rotate = 0,
  bool autoCorrectionAngle = true,
  CompressFormat format = CompressFormat.jpeg,
  bool keepExif = false,
  int numberOfRetries = 5,
}) async {
  if (numberOfRetries <= 0) {
    throw "numberOfRetries can't be null or less than 0";
  }
  if (!File(path).existsSync()) {
    throw "Image file ($path) does not exist.";
  }

  final support = await _validator.checkSupportPlatform(format);
  if (!support) {
    return null;
  }

  final result = await _channel.invokeMethod("compressWithFile", [
    path,
    minWidth,
    minHeight,
    quality,
    rotate,
    autoCorrectionAngle,
    _convertTypeToInt(format),
    keepExif,
    inSampleSize,
    numberOfRetries
  ]);
  return result;
}