mirror of
https://gitee.com/java110/MicroCommunityWeb.git
synced 2026-02-24 21:59:12 +08:00
优化代码
This commit is contained in:
parent
a2992980f6
commit
04fbd11755
@ -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);
|
||||
//关闭拍照摄像头
|
||||
|
||||
@ -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{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user