cropImage static method

Future cropImage(
  1. String path,
  2. CropAspectRatio? aspectRatio,
  3. List<CropAspectRatioPreset>? aspectRatioPresets
)

从相册取图片/视频 裁剪图片

Implementation

// static Future getGallery(
//   BuildContext context, {
//   int? count = 1,
//   ImagePickType type = ImagePickType.common,
//   List<AssetEntity>? selectedAssets,
//   Color? themeColor,
// }) async {
//   final List<AssetEntity>? result = await AssetPicker.pickAssets(
//     context,
//     pickerConfig: AssetPickerConfig(
//       textDelegate: assetPickerTextDelegateFromLocale(
//         const Locale('zh', 'CN'),
//       ),
//       selectedAssets: selectedAssets ?? [],
//       requestType: imagePickType[type]!,
//       maxAssets: count!,
//       themeColor: themeColor,
//       specialPickerType: count == 1 ? SpecialPickerType.noPreview : null,
//     ),
//   );
//   if (result != null) {
//     var assets = List<AssetEntity>.from(result);
//     List<File> fileList = [];
//     for (var element in assets) {
//       File? file = await element.file;
//       fileList.add(file!);
//     }
//     return [fileList, assets];
//   }
// }

// /// 从相机取图片/视频
// ///
// /// maxTime 单位:s
// static Future getCamera(
//   BuildContext context, {
//   int? count = 1,
//   ImagePickType type = ImagePickType.common,
//   List<AssetEntity>? selectedAssets,
//   int? maxTime,
//   bool? isSave = false,
// }) async {
//   File? fileToBeHandle;
//   final AssetEntity? result = await CameraPicker.pickFromCamera(
//     context,
//     pickerConfig: CameraPickerConfig(
//       enableRecording: true,
//       enableTapRecording: true,
//       textDelegate: cameraPickerTextDelegateFromLocale(
//         const Locale('zh', 'CN'),
//       ),
//       maximumRecordingDuration: Duration(seconds: maxTime ?? 15),
//       onEntitySaving: !isSave!
//           ? (context, viewType, file) {
//               fileToBeHandle = file;
//               Navigator.of(context)
//                 ..pop()
//                 ..pop();
//             }
//           : null,
//     ),
//   );
//   if (result != null) {
//     fileToBeHandle = await result.file;
//   }
//   return fileToBeHandle;
// }

/// 裁剪图片
static Future cropImage(String path, CropAspectRatio? aspectRatio,
    List<CropAspectRatioPreset>? aspectRatioPresets) async {
  CroppedFile? croppedFile = await ImageCropper().cropImage(
    sourcePath: path,
    compressQuality: 100,
    aspectRatio: aspectRatio ?? const CropAspectRatio(ratioX: 1, ratioY: 1),
    aspectRatioPresets: aspectRatioPresets ??
        [
          CropAspectRatioPreset.square,
        ],
    uiSettings: [
      AndroidUiSettings(
        toolbarTitle: '裁剪图片',
        toolbarColor: Colors.deepOrange,
        toolbarWidgetColor: Colors.white,
        lockAspectRatio: true,
      ),
      IOSUiSettings(
        title: '裁剪图片',
        doneButtonTitle: "完成",
        cancelButtonTitle: "取消",
        aspectRatioLockEnabled: true,
        rotateButtonsHidden: true,
        resetButtonHidden: true,
        aspectRatioPickerButtonHidden: true,
      ),
    ],
  );
  return croppedFile;
}