我想用HTML5像这那样拍摄移动相机
我已经尝试使用下面的方法,但它需要点击某个地方打开相机,这意味着我无法预览图像在现场。
<input id="fileselect" type="file" accept="image/*" capture="camera">我还找到了另一个方法,它使用了一个名为"getUserMedia“的函数,但它不支持IOS8。
那么,如何用HTML5实现移动相机的捕获呢?
请帮帮忙。
发布于 2015-02-02 04:46:51
下面是一个使用HTML5在屏幕上放置视频查看器的简单示例,该示例还允许您捕获静止图像。它已经在Chrome版本40.0.2214.93或更高版本上进行了测试。这是在MVC应用程序中完成的。如果用这段代码替换Index.cshtml中的标记,它应该运行良好。惟一的其他依赖项是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>发布于 2014-11-26 08:37:26
尝试使用一些占位符图像。
https://stackoverflow.com/questions/27144274
复制相似问题