[英]How to use jpeg stream from IP Webcam app as src in html5 video tag?
[英]Get the src of an image from HTML5 webcam
我有一個應用程序,用戶可以在其中單擊網絡攝像頭中的圖片並將其保存到數據庫中。 我已經從WebRTC添加了插件。
我的代碼如下:
<form action="process.php" method="post">
<div class="camera">
<video id="video">Video stream not available.</video>
<button id="startbutton">Take photo</button>
</div>
<canvas id="canvas">
</canvas>
<div class="output">
<img id="photo" alt="The screen capture will appear in this box.">
</div>
<script>
var myImg = document.getElementById("photo").src;
</script>
<input type="submit" onclick="alert(myImg)">
</form>
但是,當我單擊“提交”時,要檢查其通過的內容,它會發出空警報! 為什么不顯示src
?
注 :我正在幫助來自這個
首先定義一個默認的src。 然后用您拍攝的照片替換該src:
<script> var myImg = document.getElementById("photo").src; </script>
<div class="output"> <img id="photo" src="" alt="The screen capture will appear in this box."> </div>
html
和javascript
有兩個問題
單擊input type="submit"
時, img
src
仍設置為占位符圖像,刷新form
提交window
在將img
元素src
設置為photo.setAttribute('src', data);
data URI
之前,提交form
photo.setAttribute('src', data);
在takepicture
內
嘗試設置input type="submit"
disabled
屬性,以防止在takepicture
之前提交form
; 將click
事件附加到#startbutton
; 內#startbutton
click
處理程序安裝onload
事件#photo
,應該alert
data URI
的<img>
src
設定為后data URI
的表示canvas
從設置圖像video
內onload
處理程序; 將input type="submit"
disabled
屬性設置為false
以允許提交form
。
還請注意,如果不使用https:
協議,則可能會發生錯誤。
getUserMedia() no longer works on insecure origins.
To use this feature, you should consider switching your
application to a secure origin, such as HTTPS.
See [url] for more details.
<form>
<div class="camera">
<video id="video">Video stream not available.</video>
<button id="startbutton">Take photo</button>
</div>
<canvas id="canvas">
</canvas>
<div class="output">
<img id="photo" alt="The screen capture will appear in this box.">
</div>
<script>
document.getElementById("startbutton").addEventListener("click", function() {
document.getElementById("photo").onload = function() {
console.log(this.src);
alert(this.src);
document.querySelector("input[type=submit]").disabled = false;
};
})
</script>
<input type="submit" disabled>
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.