cropImage function

Future<MaskForCameraViewResult> cropImage(
  1. Image image, {
  2. required Rect flutterBoxRect,
  3. required Size desiredSize,
  4. MaskForCameraViewInsideLine? insideLine,
})

Implementation

Future<MaskForCameraViewResult> cropImage(Image image,
    {required ui.Rect flutterBoxRect,
    required ui.Size desiredSize,
    MaskForCameraViewInsideLine? insideLine}) async {
  ui.Rect imageRect = flutterToImageRect(flutterBoxRect, image);

  Image croppedImage = copyCrop(image, imageRect.left.toInt(),
      imageRect.top.toInt(), imageRect.width.toInt(), imageRect.height.toInt());

  Image resizedImage =
      copyResize(croppedImage, width: desiredSize.width.toInt());

  List<int> resizedList = encodeJpg(resizedImage);
  Uint8List resizedBytes = Uint8List.fromList(resizedList);

  MaskForCameraViewResult res =
      MaskForCameraViewResult(croppedImage: resizedBytes);

  if (insideLine != null) {
    MaskForCameraViewResult halfRes = await _cropHalfImage(
        croppedImage, insideLine,
        desiredSize: desiredSize);
    res.copyFrom(halfRes);
  }
  return res;
}