科尔多瓦相机预览无法显示图像

时间:2016-11-09 02:51:03

标签: android cordova ionic-framework cordova-plugins

我正在使用带有离子框架的Cordova-camera-preview来制作相机背景,并与Android平台上的html元素进行交互。

但是,我无法显示此插件拍摄的图像。这是我的代码:

.controller('MainCtrl', function($scope) {

    $scope.Capture = function(){
        cordova.plugins.camerapreview.takePicture({maxWidth:640, maxHeight:640});
    }

    $scope.StartCamera = function(){
        var rect = {x: 0, y: 0, width: window.innerWidth, height: window.innerHeight / 2};
        cordova.plugins.camerapreview.startCamera(rect, "back", false, false, false);

        console.log('camerapreview startCamera');

        window.addEventListener("click", function(){
            cordova.plugins.camerapreview.focus();
        });

        cordova.plugins.camerapreview.setOnPictureTakenHandler(function(src){
            console.log(src[1]);
            // Here I obtain: /data/data/com.ionicframework.ionicproject711981/files/camerapreview_09_11_2016_1039_34_preview.jpg

            document.getElementById('preview').src = src[1];
            // I put the src into the image and I get a '?' which denote 404 error.
        });
    }


    document.addEventListener("deviceready", function(){

        console.log('deviceready');
        $scope.StartCamera();

    }, false);

})

有人可以帮忙吗?

0 个答案:

没有答案