uniapp 将拍照的图片,或者选择的图片转换为base64

yarn add image-tools -D

使用

import { pathToBase64  } from 'image-tools'
btnBottom() {
                uni.chooseImage({
                    count: 6, //默认9
                    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
                    sourceType: ['album', 'camera'], //从相册选择
                    success: function(res) {
               //需要使用uni,getImageInfo获取图片的本地存储路径 uni.getImageInfo({ src: res.tempFilePaths[
0], success :(path) => { console.log(path.path,'======') pathToBase64(path.path).then(base64 => { console.log(base64) }) .catch(error => { console.error(error) }) } }) } }); }

 

posted @ 2021-09-27 16:14  龙卷风吹毁停车场  阅读(1441)  评论(0编辑  收藏  举报