[英]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.