0

我想开发一个用相机捕捉图像的移动应用程序,最初我想使用phonegap并尝试为我的visual studio2010下载和安装cordovastarter模板,但是所有的phonegap版本都给我错误......'项目类型这个安装不支持'所以想放弃使用phonegap的想法,所以接下来的事情是,是否可以在没有phonegap帮助的情况下仅使用html5与相机交互?

注意:我使用 mvc3 框架

4

1 回答 1

0

its very much posible to interact with the camera using HTML5 media API, but the support is not yet confirmed. Hence, might not work as you'd expect:

HTML part:

<video id="video" width="640" height="480" autoplay></video>
<button id="snap">Snap Photo</button>
<canvas id="canvas" width="640" height="480"></canvas>

and the javascript goes like this:

// Put event listeners into place
window.addEventListener("DOMContentLoaded", function() {
// Grab elements, create settings, etc.
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function(error) {
  console.log("Video capture error: ", error.code); 
};

// Put video listeners into place
if(navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function(stream) {
  video.src = stream;
  video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function(stream){
  video.src = window.webkitURL.createObjectURL(stream);
  video.play();
}, errBack);
}}, false);

Hope it helps, source here.

于 2013-01-17T13:18:39.543 回答