Flutter&Firebase:上传图片前的压缩
发布时间:2020-12-14 14:55:14 所属栏目:百科 来源:网络整理
导读:我想将用户在我的应用中选择的照片发送到Firebase存储.我有一个带有_imageFile属性的简单类,其设置如下: File _imageFile;_getImage() async { var fileName = await ImagePicker.pickImage(); setState(() { _imageFile = fileName; });} 之后,我发送照片
我想将用户在我的应用中选择的照片发送到Firebase存储.我有一个带有_imageFile属性的简单类,其设置如下:
File _imageFile; _getImage() async { var fileName = await ImagePicker.pickImage(); setState(() { _imageFile = fileName; }); } 之后,我发送照片与此代码: final String rand1 = "${new Random().nextInt(10000)}"; final String rand2 = "${new Random().nextInt(10000)}"; final String rand3 = "${new Random().nextInt(10000)}"; final StorageReference ref = FirebaseStorage.instance.ref().child('${rand1}_${rand2}_${rand3}.jpg'); final StorageUploadTask uploadTask = ref.put(_imageFile); final Uri downloadUrl = (await uploadTask.future).downloadUrl; print(downloadUrl); 问题是照片通常非常大.在上传之前,Flutter / Dart中是否有任何压缩和调整照片大小的方法?我很好,质量下降. 解决方法
image_picker插件目前非常简单.添加用于指定所选图像的所需尺寸/质量的选项将是直截了当的.如果您这样做,请向我们发送拉取请求!
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |