HTML5移动相机捕获
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 中的标记替换为此代码,则它应该运行正常。唯一的其他依赖项是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>
尝试使用一些占位符图像。
相关文章:
- 从移动相机拍摄图像并在上传前预览
- JavaScript访问移动相机的手电筒
- WebGL / Three.js - 由纹理着色的粒子在移动相机时不规则地闪烁
- 从网络应用程序中的网络摄像头或移动相机拍摄照片
- HTML5移动相机捕获
- 哪个相机将在移动设备中打开getUserMedia API?前部或后部
- 三个js相机移动到点
- Plupload:如何直接从相机上传(在移动设备上)
- 更新对象'相机移动时的几何图形会导致小故障-three.js
- 如何使用Matrix4.setLookAt在场景中移动相机
- 按下按钮时移动角色/相机的功能
- 如何在webgl中移动相机
- 使用TrackballControls移动光线时,相机位置错误
- 从移动相机读取文本或数字
- 相机到画布在移动应用程序
- 代码建议提供读取QR码与相机作品在桌面(不是移动)
- Three.js围绕对象(可能移动的对象)旋转相机
- HTML5移动捕获相机并生成预览框
- 尝试研究如何使用四元数来旋转沿路径移动的相机以寻找新的方向矢量
- 移动相机在它面对的方向,用三ejs