代码:
takePhoto() {
// if (this.data.canTake == true) {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: ‘high’,
success: (res) => {
//console.log(res.tempImagePath)
wx.showToast({
title: ‘上传中’,
icon: ‘loading’,
duration: 5000,
success() { },
fail() {
wx.showToast({
title: ‘上传失败,请重试’,
icon: “none”,
duration: 2000
})
},
})
//console.log(‘成功’)
//console.log(res.tempImagePath)
wx.compressImage({
src: res.tempImagePath,
quality: 45,
success(res) {
//console.log(‘压缩成功’)
//console.log(res.tempFilePath)
wx.getFileInfo({
filePath: res.tempFilePath,
success(e) {
console.log(‘1’,e.size)
if (e.size > 120000) {
// 图片大于120000B继续压缩
wx.compressImage({
src: res.tempFilePath,
quality: 40,
success(res) {
wx.getFileInfo({
filePath: res.tempFilePath,
success(e){
console.log(‘2’, e.size)
if(e.size>120000){
// 图片大于120000B继续压缩
wx.compressImage({
src: res.tempFilePath,
quality:40,
success(res){
wx.getFileInfo({
filePath: res.tempFilePath,
success(e) {
console.log(‘3’,e.size)
}
})
wx.uploadFile({
url: app.globalData.url+‘user/Upload’,
filePath: res.tempFilePath,
name: ‘avatar’,
success(res) {
//console.log(res)
//console.log(res.data)
var resdata = JSON.parse(res.data)
//console.log(resdata)
wx.navigateTo({
url: ‘/pages/point/pelvispoint/pelvispoint?img=’ + resdata.url,
})
}
})
}
})
} else{
wx.uploadFile({
url: app.globalData.url+‘user/Upload’,
filePath: res.tempFilePath,
name: ‘avatar’,
success(res) {
//console.log(res)
//console.log(res.data)
var resdata = JSON.parse(res.data)
//console.log(resdata)
wx.navigateTo({
url: ‘/pages/point/pelvispoint/pelvispoint?img=’ + resdata.url,
})
}
})
}
}
})
}
})
} else {
// 图片小于等于120000B上传
wx.uploadFile({
url: app.globalData.url+‘user/Upload’,
filePath: res.tempFilePath,
name: ‘avatar’,
success(res) {
//console.log(res)
//console.log(res.data)
var resdata = JSON.parse(res.data)
//console.log(resdata)
wx.navigateTo({
url: ‘/pages/point/pelvispoint/pelvispoint?img=’ + resdata.url,
})
}
})
}
}
})
},
fail(res) {
//console.log(‘压缩失败’, res)
}
})
}
})
// } else {
// wx.showToast({
// title: ‘请横向拍照’,
// icon: ‘none’,
// duration: 2000
// })
// return false
// }
},
打印结果:
1 121918
2 121935
3 121945
怎么越压缩越大了
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)