crop_image_utils.dart
2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import 'package:flutter/material.dart';
import 'package:image_cropper/image_cropper.dart';
class CropImageUtils {
static cropImage(BuildContext context, String path) async {
final croppedFile = await ImageCropper().cropImage(
sourcePath: path,
compressFormat: ImageCompressFormat.jpg,
compressQuality: 100,
uiSettings: [
AndroidUiSettings(
// backgroundColor: Colors.red,
// toolbarTitle: 'Cropper',
// toolbarColor: Colors.deepOrange,
// toolbarWidgetColor: Colors.white,
// initAspectRatio: CropAspectRatioPreset.ratio5x4,
cropStyle: CropStyle.rectangle,
aspectRatioPresets: [CropAspectRatioPreset.ratio5x4],
hideBottomControls: true,
lockAspectRatio: true),
IOSUiSettings(
// title: 'Cropper',
// rotateButtonsHidden: true,
// rotateClockwiseButtonHidden: true,
cropStyle: CropStyle.rectangle,
aspectRatioPresets: [CropAspectRatioPreset.ratio5x4],
resetAspectRatioEnabled: false,
doneButtonTitle: '确定',
cancelButtonTitle: '取消',
aspectRatioLockEnabled: true),
// AndroidUiSettings(
// toolbarTitle: '裁剪',
// toolbarColor: Colors.white,
// toolbarWidgetColor: Colors.white,
// initAspectRatio: CropAspectRatioPreset.square,
// lockAspectRatio: false,
// aspectRatioPresets: [
// // CropAspectRatioPreset.original,
// // CropAspectRatioPreset.square,
// CropAspectRatioPreset.ratio5x4,
// // CropAspectRatioPresetCustom(),
// ],
// ),
// IOSUiSettings(
// title: '裁剪',
// aspectRatioPresets: [
// // CropAspectRatioPreset.original,
// // CropAspectRatioPreset.square,
// CropAspectRatioPreset.ratio5x4,
// // CropAspectRatioPresetCustom(),
// ],
// ),
WebUiSettings(
context: context,
presentStyle: WebPresentStyle.dialog,
size: const CropperSize(
width: 500,
height:400,
),
),
],
);
return croppedFile;
}
}
// class CropAspectRatioPresetCustom implements CropAspectRatioPresetData {
// @override
// (int, int)? get data => (5, 4);
// @override
// String get name => '5x4';
// }