flutter获取本地图片高度、宽度

  /*获取本地图片宽度
  * */
  getLocalImageWidth(String path){
   
    int width;
    Completer<int> completer = new Completer<int>();
    Image image = Image.file(File.fromUri(Uri.parse(path)));
    // 预先获取图片信息
    image.image.resolve(new ImageConfiguration()).addListener(
        new ImageStreamListener((ImageInfo info, bool _) {
   
          width = info.image.width;
          print('height===$width');
          completer.complete(width);
        }));
    return completer.future;
  }

  /*获取本地图片高度
  * */
  getLocalImageHeight(String path){
   
    int height;
    Completer<int> completer = new Completer<int>();
    Image image = Image.file(File.fromUri(Uri.parse(path)));
    // 预先获取图片信息
    image.image.resolve(new ImageConfiguration()).addListener(
        new ImageStreamListener((ImageInfo info, bool _) {
   
          height = info.image.height;
          print('height===$height');
          completer.complete(height);
        }));
    return completer.future;
  }
//使用
int originalWidth,originalHeight;
originalWidth =  await Utils().getLocalImageWidth(imagePath);
originalHeight = await Utils().getLocalImageHeight(imagePath);

///======
//加载file类型的图片
return Image.file(imageFile,
           width: 200.w,
           height: 200.w,
           fit: BoxFit.fill,
           frameBuilder: (context, child, frame, wasSynchronouslyLoaded){
   
           		//加载完成,显示图片
               if(wasSynchronouslyLoaded){
   
                    return child;
                    }
                    //加载中,添加透明渐变
                    return AnimatedOpacity(
                            child: child,
                              opacity: frame == null ? 0 : 1,
                              duration: const Duration(seconds: 4),
                              curve: Curves.easeOut,
                       );
                       }),

//加载Uint8List类型的图片
return Image.memory(imageUint8List);
//如果得到的图片是base64加密的字符串,将字符串反编译出Uint8List数组后再加载
Image.memory(Base64Decoder().convert(slideImageBase64)));


相关推荐

  1. flutter获取本地图片高度宽度

    2024-01-07 10:30:06       57 阅读
  2. flutter image_picker 执行拍照的图片怎么保存到本地

    2024-01-07 10:30:06       37 阅读
  3. js获取dom元素的宽度数值

    2024-01-07 10:30:06       62 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-07 10:30:06       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-07 10:30:06       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-07 10:30:06       87 阅读
  4. Python语言-面向对象

    2024-01-07 10:30:06       96 阅读

热门阅读

  1. PyCharm自动化环境部署

    2024-01-07 10:30:06       56 阅读
  2. LeetCode刷题--- 解码方法

    2024-01-07 10:30:06       64 阅读
  3. React面试题

    2024-01-07 10:30:06       65 阅读