![](/img/trans.png)
[英]crop ratio getting changed when expanding crop area in image_cropper flutter
[英]Flutter i trying to crop/resize image into 1:1 ratio but i got a problem when i use image_cropper package
我正在嘗試裁剪從畫廊檢索的圖像或拍照,我需要將圖像調整為 1:1 大小並將其上傳到 firebase
這是我已經嘗試過的代碼,但我遇到了一些錯誤
Future<Null> _cropImage(File image) async {
File? croppedImage = await ImageCropper.cropImage(
sourcePath: image.path,
maxWidth: 1080,
maxHeight: 1080,
aspectRatio: CropAspectRatio(ratioX: 1.0, ratioY: 1.0)
);
if (croppedImage != null) {
imageFile = croppedImage ;
setState(() {});
}
}
這是我用來獲取圖像和裁剪圖像的代碼
下面是我用來毫無問題地拍攝圖像的原始代碼
Future _getCameraImage() async {
final image = await ImagePicker().pickImage(
source: ImageSource.camera,
imageQuality: 40,
maxHeight: 800,
maxWidth: 800);
setState(() {
_image = File(image!.path);
});
}
這是我從 flutter 得到的錯誤
當我將 _getCameraImage 放在我的 TextButton.icon 中時,像這樣按下。 他們什么都沒給我
TextButton.icon(
onPressed: () => _getCameraImage,
icon: const Icon(Icons.camera_alt),
label: const Text('Camera'),
),
我想從相機獲取圖像並將其顯示在我的 imageview 上
我認為圖像裁剪器庫的自述文件沒有正確更新,或者從他們的角度來看這是一個錯誤,這就是為什么他們顯示ImageCropper.cropImage
而不是ImageCropper().cropImage
的原因。
根據圖像裁剪器庫示例,您必須先創建圖像裁剪器 object 才能使用裁剪機制,因為cropImage
不是 static 方法。
所以嘗試使用ImageCropper().cropImage
Future<Null> _cropImage(File image) async {
File? croppedImage = await ImageCropper().cropImage(
sourcePath: image.path,
maxWidth: 1080,
maxHeight: 1080,
aspectRatio: CropAspectRatio(ratioX: 1.0, ratioY: 1.0)
);
if (croppedImage != null) {
imageFile = croppedImage ;
setState(() {});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.