Phonegap实时相机捕获

时间:2015-03-06 17:33:49

标签: javascript cordova

我想构建一个应用程序,其中我的页面背景是来自相机的图像(实时,随着我的移动更新)

有人知道插件或捕捉相机的方法吗?查看' div上的画布或背景图片?

1 个答案:

答案 0 :(得分:1)

可能的插件:https://github.com/shaithana/cordova-plugin-wezka-nativecamera

您无法解决问题,无法将捕获的图像放在画布元素上:

var options = {
    quality: 50,
    destinationType: Camera.DestinationType.DATA_URL,
    encodingType: Camera.EncodingType.JPEG,
    targetWidth: window.innerWidth,
    targetHeight: window.innerHeight,
    correctOrientation: true
};

navigator.camera.getPicture(function (imageData) {

  var canvas = document.getElementById("c");
  var ctx = canvas.getContext("2d");

  var image = new Image();
  image.src = "data:image/jpeg;base64," + imageData;
  image.onload = function() {
    ctx.drawImage(image, 0, 0);
  };

}, function (err) {
   console.log(err);
// An error occurred. Show a message to the user
}, options);

风格:

* { margin: 0; padding: 0;}

body, html { height:100%; }

#c {
    position:absolute;
    width:100%;
    height:100%;
}