截取視頻第一幀作為預(yù)覽圖片

截取視頻第一幀作為預(yù)覽圖片

capture screen(function(){var video, output;var scale =0.8;var initialize =function() {output =document.getElementById("output");video =document.getElementById("video");video.addEventListener('loadeddata',captureImage);};var captureImage =function() {var canvas =document.createElement("canvas");? ? ? ? ? ? canvas.width = video.videoWidth * scale;? ? ? ? ? ? canvas.height = video.videoHeight * scale;? ? ? ? ? ? canvas.getContext('2d').drawImage(video,0,0, canvas.width, canvas.height);var img =document.createElement("img");? ? ? ? ? ? img.src = canvas.toDataURL("image/png");? ? ? ? ? ? output.appendChild(img);}; initialize();})();

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在很多情況下我們用 input[type="file"] 上傳圖片的時(shí)候都希望有一個(gè)預(yù)覽效果,最后才會(huì)將表單一起提...
    Sharise_Mo佩珊閱讀 3,710評(píng)論 8 11
  • 一:canvas簡介 1.1什么是canvas? ①:canvas是HTML5提供的一種新標(biāo)簽 ②:HTML5 ...
    GreenHand1閱讀 4,880評(píng)論 2 32
  • H5 meta詳解 viewport width:控制 viewport 的大小,可以指定的一個(gè)值,如果 600,...
    FConfidence閱讀 888評(píng)論 0 3
  • 單例模式 適用場景:可能會(huì)在場景中使用到對(duì)象,但只有一個(gè)實(shí)例,加載時(shí)并不主動(dòng)創(chuàng)建,需要時(shí)才創(chuàng)建 最常見的單例模式,...
    Obeing閱讀 2,315評(píng)論 1 10
  • 工廠模式類似于現(xiàn)實(shí)生活中的工廠可以產(chǎn)生大量相似的商品,去做同樣的事情,實(shí)現(xiàn)同樣的效果;這時(shí)候需要使用工廠模式。簡單...
    舟漁行舟閱讀 8,130評(píng)論 2 17

友情鏈接更多精彩內(nèi)容