科尔多瓦1.7访问摄像头

时间:2012-07-05 13:21:52

标签: iphone cordova

嗨我以前制作过iPhone应用程序,但我是混合应用的新手,只是想知道如何通过cordova访问相机功能?我已经尝试了一些教程,但是当我按下xcode中的按钮时,似乎没有任何事情发生,它表示已收到内存警告。有人可以帮忙吗?

继承人到目前为止我所尝试过的事情

<!DOCTYPE html>
<html>
    <head>
        <title>Capture Photo</title>

        <script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
        <script type="text/javascript" charset="utf-8">

            var pictureSource,
                destinationType

            document.addEventListener("deviceready",loaded,false);

            function loaded() {
                pictureSource=navigator.camera.PictureSourceType;
                destinationType=navigator.camera.DestinationType;
            }

            function getPhoto(imageData) {
                var smallImage = document.getElementById('smallImage');

                smallImage.style.display = 'block';

                smallImage.src = "data:image/jpeg;base64," + imageData;
            }

            function capturePhoto() {
                navigator.camera.getPicture(getPhoto, onFail, { quality: 50 });
            }

            function onFail(message) {
                alert('Failed because: ' + message);
            }

            </script>
    </head>
    <body>
        <button onclick="capturePhoto();">Capture Photo</button> <br>
        <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
    </body>
</html>

1 个答案:

答案 0 :(得分:1)

您违反了使用过多内存的数据网址。切换到文件uri。

function getPhoto(imageData) {
    var smallImage = document.getElementById('smallImage');

    smallImage.style.display = 'block';

    smallImage.src = imageData;
}

function capturePhoto() {
    navigator.camera.getPicture(getPhoto, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI });
}