-
-
{{ navTitle }}
@@ -34,6 +32,8 @@
@@ -219,10 +210,24 @@ export default {
this.$toast('相机尚未就绪,请稍候')
return
}
+ // 按取景框比例(约 1.43:1)从视频中心裁剪,与框内可视区域(object-fit: cover)保持一致
+ const frameAspect = 1.43
+ const vw = video.videoWidth
+ const vh = video.videoHeight
+ let sw, sh
+ if (vw / vh > frameAspect) {
+ sh = vh
+ sw = Math.round(vh * frameAspect)
+ } else {
+ sw = vw
+ sh = Math.round(vw / frameAspect)
+ }
+ const sx = Math.round((vw - sw) / 2)
+ const sy = Math.round((vh - sh) / 2)
const canvas = document.createElement('canvas')
- canvas.width = video.videoWidth
- canvas.height = video.videoHeight
- canvas.getContext('2d').drawImage(video, 0, 0)
+ canvas.width = sw
+ canvas.height = sh
+ canvas.getContext('2d').drawImage(video, sx, sy, sw, sh, 0, 0, sw, sh)
const dataURL = canvas.toDataURL('image/jpeg', 0.92)
canvas.toBlob(blob => {
if (!blob) {