如何使用 webcam.js 打开移动设备的后置摄像头?

问题描述 投票:0回答:4

我正在使用 webcam.js https://github.com/jhuckaby/webcamjs 在移动设备中,前置摄像头默认打开。我想将默认设置更改为后置摄像头。 有没有办法更换摄像头设备?

javascript html google-chrome webcam.js
4个回答
5
投票
<script src="/js/webcamjs/webcam.js"></script>

<div id="my_camera" style="width:320px; height:240px;"></div>
<div id="my_result"></div>

<script language="JavaScript">
    Webcam.set('constraints',{
        facingMode: "environment"
    });
    Webcam.attach( '#my_camera' );

    function take_snapshot() {
        Webcam.snap( function(data_uri) {
            document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>';
        } );
    }
</script>

<a href="javascript:void(take_snapshot())">Take Snapshot</a>

4
投票
 var constraints = {
    video: true,
    facingMode: "environment"
};

2
投票

在我的例子中,为了使其工作,我必须像这样声明相机设置:

Webcam.set({
 width: 250,
 height: 200,
 image_format: 'jpeg',
 jpeg_quality: 90,
 // I add this object constraints
 constraints: {
   facingMode: 'environment'
 }
});

0
投票

var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); 如果(是移动设备){

 Webcam.set({
        width: 250,
        height: 200,
        image_format: 'jpg',
        jpeg_quality: 90,
        dest_width: 150,
        dest_height: 150, 
         constraints: {

faceingMode:“环境” }
});

  } 
© www.soinside.com 2019 - 2024. All rights reserved.