cropImage static method

Future<(InputImage, Image, File)> cropImage(
  1. (CameraImage, RootIsolateToken, double, double, Orientation) args
)

Implementation

static Future<(InputImage, img.Image, File)> cropImage(
    (
      CameraImage image,
      RootIsolateToken token,
      double heightInterestFactor,
      double widthInterestFactor,
      Orientation orientation
    ) args) async {
  BackgroundIsolateBinaryMessenger.ensureInitialized(args.$2);

  num angleRotate = Platform.isIOS ? 0 : 90;

  img.Image convertedImage =
      img.copyRotate(convertYUV420ToImage(args.$1), angle: angleRotate);

  /* img.adjustColor(
      img.contrast(,
          contrast: 1000),
      brightness: 5,
      exposure: 5,
      gamma: 0.5,
      8
      saturation: -5);
*/

  Directory directory = await getApplicationDocumentsDirectory();

  File file =
      await File("${directory.path}/tempImage.jpg").create(recursive: true);

  file.writeAsBytesSync(img.encodeJpg(img.copyCrop(
    convertedImage,
    x: (args.$1.height - (args.$1.height * args.$4)) ~/ 2,
    y: (args.$1.width - (args.$1.width * args.$3)) ~/
        (Platform.isIOS ? 1 : 2),
    height: (args.$1.width * args.$3 * (Platform.isIOS ? 1.5 : 1)).toInt(),
    width: (args.$1.height * args.$4).toInt(),
  )));

  return (InputImage.fromFile(file), convertedImage, file);
}