[英]HTML5 mobile camera capture
我想用HTML5做移动相机拍摄像这样
我尝试使用下面的方法,但是它需要单击某个位置以打开相机,这意味着我无法实时预览图像。
<input id="fileselect" type="file" accept="image/*" capture="camera">
我还找到了另一种方法,该方法使用了一个名为“ getUserMedia ”的函数,但IOS8不支持该方法。
那么如何使用HTML5来实现移动摄像头捕获呢?
请帮忙。
以下是使用HTML5在屏幕上放置视频查看器的简单示例,该视频查看器还允许您捕获静止图像。 已在Chrome版本40.0.2214.93或更高版本上进行了测试。 它已经在MVC应用中完成。 如果用此代码替换Index.cshtml中的标记,则应运行OK。 唯一的其他依赖性是jquery。
@{
ViewBag.Title = "Home Page";
}
<style>
.videostream, #cssfilters-stream, #screenshot {
width: 307px;
height: 250px;
}
.videostream, #cssfilters-stream {
background: rgba(255,255,255,0.5);
border: 1px solid #ccc;
}
#screenshot {
vertical-align: top;
}
</style>
<div style="text-align:center;">
@*<div style="text-align:center;">*@
<div style="float:left;">
<video id="basic-stream" class="videostream" autoplay></video>
<p><button id="capture-button">Capture video</button></p>
</div>
<div style="float:left; padding-left:20px;">
<button id="SaveImageBtn" style="vertical-align:top; margin-top:100px; margin-right:20px;">Save -></button>
<canvas id="outputCanvas" class="videostream"></canvas>
</div>
</div>
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery-ui-1.8.24.js"></script>
<script>
var video = document.querySelector('#basic-stream');
var button = document.querySelector('#capture-button');
var localMediaStream = null;
var canvas = document.querySelector('outputCanvas');
$(document).ready(function () {
$("#capture-button").click(function () {
RunIt();
});
$("#SaveImageBtn").click(function () {
var cvs = $("#outputCanvas")[0];
var ctx = cvs.getContext('2d');
ctx.drawImage(video, 0, 0, 300, 150);
console.log("Got here 01");
});
var videoObj = {"video": true};
var errBack = function (error) { alert("An error");};
function RunIt() {
navigator.webkitGetUserMedia(
{ "video": true, "audio": true },
function (s) {
video.src =
window.webkitURL.createObjectURL(s);
video.controls = true;
localMediaStream = s;
video.play();
},
function (e) { console.log(e); }
);
};
});
</script>
尝试使用一些占位符图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.