以下是我用于使用HTML5功能显示CAM的代码,运行正常我可以剪切照片并在画布中轻松查看。问题是我不知道如何禁用此相机功能。假设我现在已经剪了一张照片,我想做其他的事情,但相机仍然保持闪光灯(那些闪光灯的相机/笔记本电脑)。
jQuery('#snap_upload').on('click', function() {
jQuery('#camer_div').show();
var video = document.querySelector("#vid");
var canvas = document.querySelector('#canvas');
var ctx = canvas.getContext('2d');
var onCameraFail = function(e) {
console.log('Camera did not work.', e);
};
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia({video: true}, function(stream) {
video.src = window.URL.createObjectURL(stream);
localMediaStream = stream;
}, onCameraFail);
jQuery('#take_picture').on('click', function() {
if (localMediaStream) {
ctx.drawImage(video, 0, 0);
}
});
});