Flutter 压缩相机图像
Flutter Compress Camera Image
我想通过相机点开照片,想压缩后上传到服务器
我已经包含了图像压缩依赖项,它向我显示错误 The getter 'absolute' isn't defined for the type 'PickedFile'.
写了点击图片上传到服务器的代码
// 从相机拍照
Widget bottomSheet() {
return Container(
height: 100.0,
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(
horizontal: 20,
vertical: 20,
),
child: Column(
children: <Widget>[
Text(
"Take A Picture",
style: TextStyle(
fontSize: 20.0,
),
),
SizedBox(
height: 20,
),
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
// ignore: deprecated_member_use
FlatButton.icon(
icon: Icon(Icons.camera),
onPressed: () {
takePhoto(ImageSource.camera);
},
label: Text("Camera"),
),
])
],
),
);
}
void takePhoto(source) async {
final pickedFile = await _picker.getImage(
source: source,
);
setState(() {
_imageFile = pickedFile;
});
await FlutterImageCompress.compressWithFile(
_imageFile.absolute.path,
minWidth: 2300,
minHeight: 1500,
quality: 94,
rotate: 90,
);
}
而不是使用 FlutterImageCompress.compressWithFile 只需在 _picker.getImage
中添加 imageQuality
_picker.getImage(
source:ImageSource.camera,
minWidth: 2300,
minHeight: 1500,
imageQuality: 75
)
随着图片质量值大小的改变
我想通过相机点开照片,想压缩后上传到服务器
我已经包含了图像压缩依赖项,它向我显示错误 The getter 'absolute' isn't defined for the type 'PickedFile'.
写了点击图片上传到服务器的代码 // 从相机拍照
Widget bottomSheet() {
return Container(
height: 100.0,
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(
horizontal: 20,
vertical: 20,
),
child: Column(
children: <Widget>[
Text(
"Take A Picture",
style: TextStyle(
fontSize: 20.0,
),
),
SizedBox(
height: 20,
),
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
// ignore: deprecated_member_use
FlatButton.icon(
icon: Icon(Icons.camera),
onPressed: () {
takePhoto(ImageSource.camera);
},
label: Text("Camera"),
),
])
],
),
);
}
void takePhoto(source) async {
final pickedFile = await _picker.getImage(
source: source,
);
setState(() {
_imageFile = pickedFile;
});
await FlutterImageCompress.compressWithFile(
_imageFile.absolute.path,
minWidth: 2300,
minHeight: 1500,
quality: 94,
rotate: 90,
);
}
而不是使用 FlutterImageCompress.compressWithFile 只需在 _picker.getImage
中添加 imageQuality_picker.getImage(
source:ImageSource.camera,
minWidth: 2300,
minHeight: 1500,
imageQuality: 75
)
随着图片质量值大小的改变