PhoneGap CameraAPI三次返回(null)

时间:2011-04-12 19:42:21

标签: iphone cordova

当从电话库中选择任何照片时,我写的以下代码总是返回空值。

<script type="text/javascript">
        var imgData = null;
        var pictureSource = null;
        var destinationType = null;

    function onLoad() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }

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

        function selectPhotoFromLibrary(e) {
            if (e) e.preventDefault();

            navigator.camera.getPicture(onSuccess, onFail, 
                {
                    sourceType: pictureSource.PHOTOLIBRARY,
                    destinationType: destinationType.DATA_URL
                }
            );
        }

        function selectPhotoFromAlbums(e) {
            if (e) e.preventDefault();

            navigator.camera.getPicture(onSuccess, onFail, 
                {
                    quality: 50,
                    sourceType: pictureSource.SAVEDPHOTOALBUM,
                    destinationType: destinationType.DATA_URL
                }
            );
        }

        function onSuccess(data) {
            alert(data);
            imgData = data;
        }

        function onFail(msg) {
            navigator.notification.alert(msg, null, "Error", "OK");
        }
    </script>

HTML

<div id="buttons">
                <input value="Select Photo From Library" style="margin: 5px; width: 95%;" onclick="selectPhotoFromLibrary(event)" type="button">
                <br>
                <input value="Select Photo From Albums" style="margin: 5px; width: 95%;" onclick="selectPhotoFromAlbums(event)" type="button">
            </div>

0 个答案:

没有答案