久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      通過H5實現(xiàn)拍照功能的實例詳解

      HTML5拍照首先,我們看看HTML代碼結(jié)構(gòu),當(dāng)然,這部分的DOM內(nèi)容應(yīng)該是在用戶允許使用其攝像頭事件出發(fā)后,動態(tài)加載生成的,感興趣的朋友可以了解下 演示地址: HTML5拍照演示
      首先,我們看看HTML代碼結(jié)構(gòu),當(dāng)然,這部分的DOM內(nèi)容應(yīng)該是在用戶允許使用其攝像頭事件出發(fā)后,動態(tài)加載生成的。
      注意: 我們采用的是 640X480的分辨率,如果采用JS動態(tài)生成,那么您是可以靈活控制分辨率的。

      代碼如下:

      <!--   聲明: 此p應(yīng)該在允許使用webcam,網(wǎng)絡(luò)攝像頭之后動態(tài)生成   寬高: 640 *480,當(dāng)然,可以動態(tài)控制啦!   -->   <!--   Ide  all  y these elements aren't created until it's confirmed that the   client supports video/camera, but   for   the sake of illustrating the   elements involved, they are created with markup (not   JavaScript  )   -->   <video id="video"   width  ="640"   height  ="480"   autoplay  ></video>   <button id="snap">Snap Photo</button>   <  canvas   id="canvas" width="640" height="480"></canvas>

      JavaScript
      只要上面的HTML元素創(chuàng)建完成,那么JavaScript部分將簡單的超乎你想象的簡單:

      代碼如下:

      // 設(shè)置事件監(jiān)聽,DOM內(nèi)容加載完成,和  jQuery  的$.ready() 效果差不多。   window.addEvent  List  ener("DOMContentLoaded", function() {   // canvas 元素將用于抓拍   var canvas =   document  .getElementById("canvas"),   context = canvas.getContext("2d"),   // video 元素,將用于接收并播放攝像頭 的數(shù)據(jù)流   video = document.getElementById("video"),   videoObj = { "video": true },   // 一個出錯的  回調(diào)函數(shù)  ,在控制臺打印出錯信息   errBack = function(error) {   if  ("  object  " === typeof window.console){   console.log("Video capture error: ", error.code);   }   };   // Put video listeners into place   // 針對標(biāo)準(zhǔn)的瀏覽器   if(navigator.getUserMedia) { // Standard   navigator.getUserMedia(videoObj, function(stream) {   video.src = stream;   video.play();   }, errBack);   }   else   if(navigator.webkitGetUserMedia) { // WebKit-prefixed   navigator.webkitGetUserMedia(videoObj, function(stream){   video.src = window.webkitURL.createObjectURL(stream);   video.play();   }, errBack);   }   // 對拍照  按鈕  的事件監(jiān)聽   document.getElementById("snap").addEventListener("click", function() {   // 畫到畫布上   context.drawImage(video, 0, 0, 640, 480);   });   }, false);

      最后,記得講您的網(wǎng)頁放到web服務(wù)器下面,然后通過http協(xié)議來訪問哦。
      另外,需要瀏覽器版本較新,并且支持HTML5的相關(guān)新特性才可以。
      譯者不算稱職啦,沒有按原文來翻譯。使用的瀏覽器是chrome 28。
      最后,貼上完整的代碼,比較呆板。

      代碼如下:

      <!DOCTYPE html>   <html>   <head>   <title> 瀏覽器webcamera </title>   <meta name="Generator" content="EditPlus">   <meta name="Author" content="renfufei@qq.com">   <meta name="Description" content="inveted by: http://davidwalsh.name/browser-camera">   <script>   // 設(shè)置事件監(jiān)聽,DOM內(nèi)容加載完成,和jQuery的$.ready() 效果差不多。   window.addEventListener("DOMContentLoaded", function() {   // canvas 元素將用于抓拍   var canvas = document.getElementById("canvas"),   context = canvas.getContext("2d"),   // video 元素,將用于接收并播放攝像頭 的數(shù)據(jù)流   video = document.getElementById("video"),   videoObj = { "video": true },   // 一個出錯的回調(diào)函數(shù),在控制臺打印出錯信息   errBack = function(error) {   if("object" === typeof window.console){   console.log("Video capture error: ", error.code);   }   };   // Put video listeners into place   // 針對標(biāo)準(zhǔn)的瀏覽器   if(navigator.getUserMedia) { // Standard   navigator.getUserMedia(videoObj, function(stream) {   video.src = stream;   video.play();   }, errBack);   } else if(navigator.webkitGetUserMedia) { // WebKit-prefixed   navigator.webkitGetUserMedia(videoObj, function(stream){   video.src = window.webkitURL.createObjectURL(stream);   video.play();   }, errBack);   }   // 對拍照按鈕的事件監(jiān)聽   document.getElementById("snap").addEventListener("click", function() {   // 畫到畫布上   context.drawImage(video, 0, 0, 640, 480);   });   }, false);   </script>   </head>   <body>   <p>   <!--   聲明: 此p應(yīng)該在允許使用webcam,網(wǎng)絡(luò)攝像頭之后動態(tài)生成   寬高: 640 *480,當(dāng)然,可以動態(tài)控制啦!   -->   <!--   Ideally these elements aren't created until it's confirmed that the   client supports video/camera, but for the sake of illustrating the   elements involved, they are created with markup (not JavaScript)   -->   <video id="video" width="640" height="480" autoplay></video>   <button id="snap">Snap Photo</button>   <canvas id="canvas" width="640" height="480"></canvas>   </p>   </body>   </html>

      【相關(guān)推薦】

      1. Html5免費視頻教程

      2. HTML5實現(xiàn)微信播放全屏的方法詳解

      3. 關(guān)于H5新標(biāo)簽的瀏覽器兼容問題的詳解

      4. 整體概述如何用H5制作網(wǎng)頁

      5. H5與傳統(tǒng)html的區(qū)別

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號