let [err, res] = await uni.chooseImage({
sourceType: ['album'],
sizeType: ['compressed']
});
不限制sizeType也可以,选择的时候不勾选【原图】一样可以复现。
完整测试Demo代码:
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<button @click="selImgs">选择图片</button>
</view>
</template>
<script>
let timer = null;
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
async selImgs(){
clearInterval(timer);
let [err, res] = await uni.chooseImage({
sourceType: ['album'],
sizeType: ['compressed']
});
if(err){
console.error('choose error:', err);
return;
}
let initStart = new Date() / 1;
timer = setInterval(async () => {
let succNum = await this.checkImgInfos(res.tempFiles);
let cost = new Date() / 1 - initStart;
this.title = '有效图片:' + succNum + ', valid for ' + cost + ' ms';
if(!succNum){
clearInterval(timer);
}
}, 100);
},
async checkImgInfos(images){
let succNum = 0;
for(let img of images){
let [err, res] = await uni.getFileInfo({filePath: img.path});
if(!err && res.size){
succNum += 1;
}
}
return succNum;
}
}
}
</script>