欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何使用HTML5實(shí)現(xiàn)拍照功能

這篇文章主要介紹“如何使用HTML5實(shí)現(xiàn)拍照功能”,在日常操作中,相信很多人在如何使用HTML5實(shí)現(xiàn)拍照功能問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”如何使用HTML5實(shí)現(xiàn)拍照功能”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

創(chuàng)新互聯(lián)建站是專業(yè)的合川網(wǎng)站建設(shè)公司,合川接單;提供成都做網(wǎng)站、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行合川網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

代碼如下:


<!--
聲明: 此div應(yīng)該在允許使用webcam,網(wǎng)絡(luò)攝像頭之后動(dòng)態(tài)生成
寬高: 640 *480,當(dāng)然,可以動(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>


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

代碼如下:


// 設(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 },
// 一個(gè)出錯(cuò)的回調(diào)函數(shù),在控制臺(tái)打印出錯(cuò)信息
errBack = function(error) {
if("object" === typeof window.console){
console.log("Video capture error: ", error.code);
}
};
// Put video listeners into place
// 針對(duì)標(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);
}
// 對(duì)拍照按鈕的事件監(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 },
// 一個(gè)出錯(cuò)的回調(diào)函數(shù),在控制臺(tái)打印出錯(cuò)信息
errBack = function(error) {
if("object" === typeof window.console){
console.log("Video capture error: ", error.code);
}
};
// Put video listeners into place
// 針對(duì)標(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);
}
// 對(duì)拍照按鈕的事件監(jiān)聽
document.getElementById("snap").addEventListener("click", function() {
// 畫到畫布上
context.drawImage(video, 0, 0, 640, 480);
});
}, false);
</script>
</head>
<body>
<div>
<!--
聲明: 此div應(yīng)該在允許使用webcam,網(wǎng)絡(luò)攝像頭之后動(dòng)態(tài)生成
寬高: 640 *480,當(dāng)然,可以動(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>
</div>
</body>
</html>

到此,關(guān)于“如何使用HTML5實(shí)現(xiàn)拍照功能”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

網(wǎng)頁標(biāo)題:如何使用HTML5實(shí)現(xiàn)拍照功能
當(dāng)前網(wǎng)址:http://chinadenli.net/article30/gjodso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司電子商務(wù)標(biāo)簽優(yōu)化品牌網(wǎng)站設(shè)計(jì)自適應(yīng)網(wǎng)站搜索引擎優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)