赞
踩
- uni.chooseImage({
- count: 1, // 默认9
- sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album'], // 从相册选择
- success: (res) => {
- this.img = res.tempFilePaths
- }
- })
- uni.getFileSystemManager().readFile({
- filePath: this.img[0],
- encoding: 'base64',
- success: r => {
- console.log("base64===="+r.data)
- },
- fail: (errr) => {
- uni.hideLoading()
- }
- })
- uni.getImageInfo({
- src: '../../static/xkm.png',
- success: (image) => {
- console.log('获取图片成功',image)
- },
- fail: (err) => {
- console.log('获取图片失败',err)
- }
- );
npm i image-tools --save-dev
import { pathToBase64, base64ToPath } from 'image-tools'
- pathToBase64('图片地址').then(base64 => {
- console.log("图片=="+base64);
- }).catch(error => {
- console.error(error)
- })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。