【问题标题】:Flutter, image_cropper, how to resize at specific ratioFlutter,image_cropper,如何以特定比例调整大小
【发布时间】:2021-11-19 08:42:37
【问题描述】:
   File? croppedImage = await ImageCropper.cropImage(
                   .......
         androidUiSettings: AndroidUiSettings(lockAspectRatio: false,)

这只允许调整大小,但不能保持特定的比例(我希望它是 1:1)。

我几乎检查了每个参数,但仍然找不到。

我怎样才能做到这一点?

【问题讨论】:

    标签: flutter dart flutter-layout flutter-dependencies flutter-animation


    【解决方案1】:

    您可以使用如下所示的aspectRatio 属性在图像裁剪器中保持 1:1 的纵横比

    aspectRatio: CropAspectRatio(ratioX: 1.0, ratioY: 1.0),
    

    图像裁剪器的完整代码

    ImageCropper.cropImage(
            sourcePath: originalImage.path,
            aspectRatio: CropAspectRatio(ratioX: 1.0, ratioY: 1.0),
            maxWidth: 1500, //optional if you want to control the width (max)
            maxHeight: 1500, //optional if you want to control the height (max)
          )
    

    【讨论】:

    • 是的,我也这样做了,但毕竟如果你想手动调整它的大小,你需要添加 lockAspectRatio:false。它会破坏 1:1
    猜你喜欢
    • 2020-05-12
    • 2021-06-01
    • 1970-01-01
    • 2014-07-21
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 2011-09-14
    相关资源
    最近更新 更多