【问题标题】:Flutter how to get width and height from picked image XFileFlutter 如何从选取的图像 XFile 中获取宽度和高度
【发布时间】:2023-02-09 17:53:15
【问题描述】:

我正在尝试调整和压缩由图片选择器包裹

但我不知道从哪里获取图像信息(宽度、高度)

我试过图像大小获取器包,但我得到了不受支持的异常

有没有一种简单的方法可以从 XFile 获取宽度和高度?

【问题讨论】:

    标签: flutter height width imagepicker


    【解决方案1】:

    你可以试试这个:

     XFile? imageFile = await ImagePicker().pickImage(source: ImageSource.camera);
    if (imageFile != null) {
      final decodedImage = await decodeImageFromList(await imageFile.readAsBytes());
    final height = decodedImage.height;  // Image height
    final width = decodedImage.width;  // Image width
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-20
      • 1970-01-01
      • 2011-05-31
      • 1970-01-01
      • 2014-07-15
      • 2010-11-18
      • 1970-01-01
      • 2015-09-04
      相关资源
      最近更新 更多