优化代码

This commit is contained in:
java110 2021-07-08 13:37:29 +08:00
parent a2992980f6
commit 04fbd11755
2 changed files with 43 additions and 8 deletions

View File

@ -154,7 +154,7 @@
idCard: '',
videoPlaying: true,
mediaStreamTrack: null,
attrs:[]
attrs: []
};
this._loadOwnerAttrSpec();
},
@ -195,10 +195,28 @@
if (vc.component.addOwnerInfo.videoPlaying) {
var canvas = document.getElementById('canvas');
var video = document.getElementById('ownerPhoto');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
let w = video.videoWidth;
// 默认按比例压缩
let h = video.videoHeight;
if (h > 1080 || w > 1080) {
let _rate = 0;
if (h > w) {
_rate = h / 1080;
h = 1080;
w = Math.floor(w / _rate);
} else {
_rate = w / 1080;
w = 1080;
h = Math.floor(h / _rate);
}
}
canvas.width = w;
canvas.height = h;
canvas.getContext('2d').drawImage(video, 0, 0);
var data = canvas.toDataURL('image/jpeg', 1.0);
var data = canvas.toDataURL('image/jpeg', 0.3);
vc.component.addOwnerInfo.ownerPhoto = data;
//document.getElementById('photo').setAttribute('src', data);
//关闭拍照摄像头

View File

@ -219,10 +219,27 @@
if (vc.component.editOwnerInfo.videoPlaying) {
var canvas = document.getElementById('canvasForEdit');
var video = document.getElementById('ownerPhotoForEdit');
canvas.width = 208;
canvas.height = 208;
canvas.getContext('2d').drawImage(video, 0, 0, 208, 208);
var data = canvas.toDataURL('image/jpeg', 1.0);
let w = video.videoWidth;
// 默认按比例压缩
let h = video.videoHeight;
if (h > 1080 || w > 1080) {
let _rate = 0;
if (h > w) {
_rate = h / 1080;
h = 1080;
w = Math.floor(w / _rate);
} else {
_rate = w / 1080;
w = 1080;
h = Math.floor(h / _rate);
}
}
canvas.width = w;
canvas.height = h;
canvas.getContext('2d').drawImage(video, 0, 0);
var data = canvas.toDataURL('image/jpeg', 0.3);
vc.component.editOwnerInfo.ownerPhoto = data;
//document.getElementById('photo').setAttribute('src', data);
}else{