fix:改用takePhotoSnapshot拍预览区域,与取景框所见即所得
This commit is contained in:
parent
3856d28629
commit
24c81b5bfe
@ -130,7 +130,7 @@
|
||||
uni.showToast({ title: '相机未就绪', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.$refs.cameraRef.takePhoto()
|
||||
this.$refs.cameraRef.takePhotoSnapshot()
|
||||
},
|
||||
onPictureTaken(e) {
|
||||
var path = ''
|
||||
@ -138,49 +138,9 @@
|
||||
path = e.detail.path || ''
|
||||
}
|
||||
if (path) {
|
||||
this.resizeToSquare(path)
|
||||
this.capturedList.push(path)
|
||||
}
|
||||
},
|
||||
// 裁剪为 1080×1080 正方形
|
||||
resizeToSquare(srcPath) {
|
||||
var that = this
|
||||
uni.getImageInfo({
|
||||
src: srcPath,
|
||||
success: function(info) {
|
||||
var w = info.width
|
||||
var h = info.height
|
||||
// 居中裁剪正方形
|
||||
var size = Math.min(w, h)
|
||||
var clipX = Math.floor((w - size) / 2)
|
||||
var clipY = Math.floor((h - size) / 2)
|
||||
// 使用 5+ 原生压缩 API 裁剪 + 缩放到 1080x1080
|
||||
plus.zip.compressImage({
|
||||
src: srcPath,
|
||||
dst: '_doc/resize_' + Date.now() + '.jpg',
|
||||
width: '1080',
|
||||
height: '1080',
|
||||
quality: 90,
|
||||
overwrite: true,
|
||||
clip: {
|
||||
x: clipX,
|
||||
y: clipY,
|
||||
width: size,
|
||||
height: size
|
||||
}
|
||||
},
|
||||
function(res) {
|
||||
that.capturedList.push(res.target)
|
||||
},
|
||||
function() {
|
||||
// 失败时用原始路径
|
||||
that.capturedList.push(srcPath)
|
||||
})
|
||||
},
|
||||
fail: function() {
|
||||
that.capturedList.push(srcPath)
|
||||
}
|
||||
})
|
||||
},
|
||||
flipCamera() {
|
||||
this.facing = this.facing === 'back' ? 'front' : 'back'
|
||||
this.$refs.cameraRef.changeFacing(this.facing)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user