sencha + Phonegap问题(navigator.camera.getPicture函数崩溃应用)

时间:2013-12-26 19:21:00

标签: android cordova sencha-touch

我是在sencha触摸框架中的新编程,我正在一个应用程序(android)工作,它必须拍照并稍后在另一个视图中显示它,但照片拍摄没有问题,但一旦我采取图片,应用程序崩溃,它甚至不会调用失败事件。我正在使用cordova的navigator.camera.getPicture函数来拍照。谁能告诉我,我错过了什么?

1 个答案:

答案 0 :(得分:0)

我确实喜欢这样你可以尝试

config: {

        cls:'cameraimageoverlay',
        items: [    
            {
                xtype: 'button',
                ui: 'confirm',
                iconCls: 'confirm',
                id:'devicecapturephoto',
                text: 'Take Photo',
                margin: '10 40',
                width: '72%',
                height: 36
            }

        ],
        listeners:[
            {
                fn: 'capturePhoto',
                event: 'tap',
                delegate: '#devicecapturephoto'
            }
        ]
    }

capturePhoto功能

 capturePhoto:function() {
    // Take picture using device camera and retrieve image as base64-encoded string
        try{


            var pictureSource;   // picture source
            var destinationType; // sets the format of returned value
            document.addEventListener("deviceready", onDeviceReady, false);
            function onDeviceReady () {
              //  alert('device ready');
                pictureSource = navigator.camera.PictureSourceType;
                destinationType = navigator.camera.DestinationType;
            }

            function onPhotoDataSuccess(imageData) {

                var smallImage = document.getElementById('smallImage');
                smallImage.style.display = 'block';
                smallImage.src = "data:image/jpeg;base64," + imageData;
            }

            // Called when a photo is successfully retrieved
            //
            function onPhotoURISuccess(imageURI) {
                // Uncomment to view the image file URI
                // console.log(imageURI);

                // Get image handle
                //
                var largeImage = document.getElementById('largeImage');

                // Unhide image elements
                //
                largeImage.style.display = 'block';

                // Show the captured photo
                // The in-line CSS rules are used to resize the image
                //
                largeImage.src = imageURI;
            }

            // A button will call this function
            //
                // Take picture using device camera and retrieve image as base64-encoded string
                navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, correctOrientation: true,
                    destinationType: destinationType.DATA_URL });


            // A button will call this function
            //
            function capturePhotoEdit() {
                // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
                navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
                    destinationType: destinationType.DATA_URL });
            }

            // A button will call this function
            //
            function getPhoto(source) {
                // Retrieve image file location from specified source
                navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
                    destinationType: destinationType.FILE_URI,
                    sourceType: source });
            }

            // Called if something bad happens.
            //
            function onFail(message) {
                alert('Failed because: ' + message);
            }
        }
        catch(err){
           // alert(err);
        }
    }

您可以参考http://docs.phonegap.com/en/2.3.0/cordova_camera_camera.md.html