【问题标题】:image_picker plugin for flutter shows unusual warning颤振的 image_picker 插件显示异常警告
【发布时间】:2019-09-18 09:48:17
【问题描述】:

我正在使用以下代码来选择具有 maxHeight/width 的图像以节省空间。

    void openGallery()async {
    var gallery = await ImagePicker.pickImage(
      source: ImageSource.gallery,
      maxHeight: maxImageSize,
      maxWidth: maxImageSize,
    );
    if (gallery!=null) {
      var bytes = await gallery.readAsBytes();
      if (DEBUG) print('Image bytes: ${bytes.length / 1024} KB');
      if (DEBUG) print('Image path: ${gallery.path}');
      setState(() {
        List<int> imageBytes = gallery.readAsBytesSync();
        _imageB64 = base64Encode(imageBytes);
        // decoded = base64Decode(_imageB64);
        if (DEBUG) print('Base64 String length: ${_imageB64.length / 1024} KB');
      });
    }
  }

我在控制台中收到以下警告:

image_picker: compressing is not supported for type (null). Returning the image with original quality
flutter: Image bytes: 153.583984375 KB
flutter: Image path: ...myimagpath.jpg
flutter: Base64 String length: 204.78125 KB

1) 一方面,我可以看到我的图像缩小了,因为它只有 200kB,但另一方面,第一行让我感到困惑。

2) 另外,我的印象是 BASE64 编码的图像尺寸变小了,因为我想将它们保存到 Firebase,将它们保存为“字节”(因为它是 153kb)会不会有问题?

【问题讨论】:

    标签: flutter dart flutter-dependencies dart-pub


    【解决方案1】:

    试试这个,我的代码运行良好。

    var selectedProfileImage;
    
    
    Future _getImage(bool fromCamera) async {
      File image;
      if (fromCamera) {
        image = await ImagePicker.pickImage(source: ImageSource.camera, maxWidth: 150.0, maxHeight: 150.0);
      } else {
        image = await ImagePicker.pickImage(source: ImageSource.gallery, maxWidth: 150.0, maxHeight: 150.0);
      }
      if (image != null) {
        // Initiate the ProgessBar
        selectedProfileImage = image;
    
      }
    }
    

    【讨论】:

    • 你的代码没有区别,我已经在做同样的事情了
    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 2020-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    • 2020-01-13
    • 2019-07-11
    相关资源
    最近更新 更多