[英]how to crop image in flutter using image_cropper package?
this is my code for function.这是我的功能代码。 I am using image_cropper package.我正在使用 image_cropper 包。 but there is some error on await ImageCropper.cropImage( sourcePath: filePath, maxHeight: 1080, maxWidth: 1080, );但是 await ImageCropper.cropImage( sourcePath: filePath, maxHeight: 1080, maxWidth: 1080, );
How to fix it?如何解决?
void _cropImage(filePath) async { File croppedImage = await ImageCropper.cropImage( sourcePath: filePath, maxHeight: 1080, maxWidth: 1080, ); if (croppedImage != null) { imageFile = croppedImage; setState(() {}); } }
static void cropImage(
{XFile? image, Function(File)? setFile, BuildContext? context,}) async {
try {
File? croppedFile = await ImageCropper().cropImage(
sourcePath: image!.path,
maxHeight: 20000,
maxWidth: 200000,
cropStyle: CropStyle.circle,
aspectRatioPresets: [
CropAspectRatioPreset.square,
CropAspectRatioPreset.ratio3x2,
CropAspectRatioPreset.original,
CropAspectRatioPreset.ratio4x3,
CropAspectRatioPreset.ratio16x9
],
androidUiSettings: const AndroidUiSettings(
toolbarTitle: 'crop',
toolbarColor: Colors.green,
toolbarWidgetColor: Colors.white
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false,
),
iosUiSettings: const IOSUiSettings(
minimumAspectRatio: 1.0,
),
);
File _image = croppedFile ?? File(image.path);
setFile!(_image);
} catch (e) {
log("Error in Cropping");
log(e.toString());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.