uniapp 选择并压缩图片

uniapp yekong 1700℃

在做app的时候经常需要上传头像,这就需要压缩图片了
使用plus.zip.compressImage 进行压缩


chooseImage() {
            var that = this;
            uni.chooseImage({
                count: 1,
                sizeType: ['compressed'],
                success: res => {
                    console.log(res);
                    plus.zip.compressImage(
                        {
                            src: res.tempFilePaths[0],
                            dst: '_doc/a.jpg',
                            quality: 70, //压缩比例
                            overwrite: true,
                            width: '350px' //图片宽度
                        },
                        function(e) {
                            //执行上传
                            that.uploadimg(e.target);
                        },
                        function(error) {
                            console.log('Compress error!');
                        }
                    );
                },
                fail: err => {
                    // #ifdef MP
                    uni.getSetting({
                        success: res => {
                            let authStatus = res.authSetting['scope.album'] && res.authSetting['scope.camera'];
                            if (!authStatus) {
                            }
                        }
                    });
                    // #endif
                }
            });
        },
喜欢 (5)