小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

要多簡(jiǎn)單就有多簡(jiǎn)單的H5拍照加水印

 昵稱33363002 2016-10-12

來一個(gè)簡(jiǎn)單粗暴的gif演示圖

先來html 內(nèi)容

<video id='video' width='320' height='240' autoplay></video> <button id='snap'>拍張照片唄</button> <canvas id='canvas' width='320' height='240' ></canvas>

一個(gè)video 一個(gè)canvas

然后js內(nèi)容
把設(shè)備啟動(dòng)下

init: function(){ var video = this.video; if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) { video.src = window.URL.createObjectURL(stream); video.play(); }); } this.bind(); }

綁定下按鈕
按鈕獲取點(diǎn)擊時(shí)的幀,和添加一下水印

font: '14px microsoft yahei', style: 'rgba(255,255,255,0.9)', text: '有一個(gè)姑娘在coding', height: 240, width: 320, draw_pic: function(){ var self = this; var context = self.canvas.getContext('2d'); context.drawImage(self.video, 0, 0, self.width, self.height); context.font = self.font; context.fillStyle = self.style; context.fillText(self.text, self.width - 140 , self.height - 10); }

這樣就結(jié)束了
附上全部代碼

<!DOCTYPE html> <html> <head> <meta charset='utf-8' /> <title>要多簡(jiǎn)單就有多簡(jiǎn)單的H5拍照加水印</title> </head> <style type='text/css'> video,canvas{ border: 1px solid #ccc; } </style> <body> <video id='video' width='320' height='240' autoplay></video> <button id='snap'>拍張照片唄</button> <canvas id='canvas' width='320' height='240' ></canvas> </body> <script type='text/javascript'> var camera = { video: document.getElementById('video'), canvas: document.getElementById('canvas'), btn: document.getElementById('snap'), font: '14px microsoft yahei', style: 'rgba(255,255,255,0.9)', text: '有一個(gè)姑娘在coding', height: 240, width: 320, draw_pic: function(){ var self = this; var context = self.canvas.getContext('2d'); context.drawImage(self.video, 0, 0, self.width, self.height); context.font = self.font; context.fillStyle = self.style; context.fillText(self.text, self.width - 140 , self.height - 10); }, bind: function(){ var self = this; self.btn.addEventListener('click', function() { self.draw_pic(); }); }, init: function(){ var video = this.video; if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) { video.src = window.URL.createObjectURL(stream); video.play(); }); } this.bind(); } }; camera.init(); </script> </html>

附上我的訂閱號(hào)二維碼,持續(xù)分享內(nèi)容哦

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多