承袭上一篇 Image_picker
这篇使用image_cropper 把选到的照片做裁切或旋转等加工
Android
AndroidManifest.xml 需要新增
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
程序部分 新增cropImage() function
由getImage()这边,取得image_picker回传的路径後,
传到cropImage()进行处理 然而传回来的结果的也是图片路径(裁切或旋转过的)
最後再赋值回imageFilePath.
getImage()里面取得的(ImageSource source) async {
final _picker = ImagePicker();
XFile? pickedFile = await _picker.pickImage(source: source);
if (pickedFile != null) {
// imageFilePath = pickedFile.path;
// print(imageFilePath);
imageFilePath = await cropImage(pickedFile.path);
}
}
Future cropImage(String pickedFilePath) async {
File? croppedFile = await ImageCropper.cropImage(
sourcePath: pickedFilePath,
aspectRatioPresets: Platform.isAndroid
? [
CropAspectRatioPreset.square,
CropAspectRatioPreset.original,
//CropAspectRatioPreset.ratio16x9
]
: [
CropAspectRatioPreset.original,
CropAspectRatioPreset.square,
//CropAspectRatioPreset.ratio16x9
],
androidUiSettings: AndroidUiSettings(
toolbarTitle: 'Cropper',
toolbarColor: Colors.blueAccent,
toolbarWidgetColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.square,
lockAspectRatio: false),
iosUiSettings: IOSUiSettings(title: 'Cropper'));
if (croppedFile != null) {
return croppedFile.path;
} else {
return null;
}
}
}
实际结果如下
下一篇为大家介绍 gallery saver
<<: Day22:[排序演算法]Merge sort - 合并排序法
>>: 自动化 End-End 测试 Nightwatch.js 之踩雷笔记:点击物件 II
上一篇介绍了Cubes,主要是考回圈的运用及判断,仔细思考之後就会发现不是那麽困难了。 今天讲解的题...
字典(Dictionary) 抽象资料结构 在字典里,有个物品,每一样东西都会跟随着一个(假设物品和...
在前面的五篇文章当中,我们提到了 SOLID 设计原则,分别为 单一功能原则 Single Resp...
「回到我在贝尔实验室(The Bell Lab)工作的日子。我们有个不严谨的发现,采用一致性的缩排...
在[Day5] 另一半疑似劈腿?! 教你用Python科技抓奸!中, 有提到只要填入申请好的LINE...