注:意请在手机上预览,PC无效果
首先, 包括 Webcam.js JavaScript
<script type="text/javascript" src="../webcam.min.js"></script>
html
<div id="results">您拍摄的图像将显示在此处..。</div>
配置一些设置并连接相机
<script language="JavaScript"> Webcam.set({ width: 320, height: 240, image_format: 'jpeg', jpeg_quality: 90 }); Webcam.attach('#my_camera'); </script>
用于处理拍摄快照并在本地显示的代码
<script language="JavaScript"> function take_snapshot() { // take snapshot and get image data Webcam.snap(function(data_uri) { // display results in page document.getElementById('results').innerHTML = '<h2>Here is your image:</h2>' + '<img src="' + data_uri + '"/>'; }); } </script>