【问题标题】:Flutter Compress Camera ImageFlutter 压缩相机图像
【发布时间】:2021-10-06 14:48:36
【问题描述】:

我想通过相机点击照片并想压缩然后上传到服务器

我已经包含了图像压缩依赖,它向我显示了错误getter 'absolute' 没有为类型'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,
);
 }

【问题讨论】:

    标签: flutter flutter-layout flutter-dependencies flutter-web flutter-image


    【解决方案1】:

    不使用 FlutterImageCompress.compressWithFile 只需在 _picker.getImage 中添加 imageQuality

    _picker.getImage(
          source:ImageSource.camera,
          minWidth: 2300,
          minHeight: 1500,
          imageQuality: 75
    )
    

    随着图像质量值大小的改变,图像的大小发生变化

    【讨论】:

    • 但假设我想通过 Internet 将图像发送到 API,最好将其保存在 tiff 中并进行压缩。
    • 是的,您可以发布具有图像质量的图像。由于每个多部分 api 都有发布的大小限制。
    猜你喜欢
    • 2019-08-22
    • 2013-11-04
    • 2023-01-25
    • 2012-09-28
    • 2011-07-26
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多