如何使用phonegap在sencha touch应用程序中启用相机功能?

时间:2012-10-01 09:04:51

标签: ios cordova sencha-touch-2

我在Sencha Touch 2中开发了一个应用程序。我想以这样的方式设计一个页面 该页面有一个默认图像,下面有一个按钮。通过单击该按钮设备相机应该打开(设备主要是iPad和iPhone),捕获图像后,可以将其存储在设备中名为“捕获”的文件夹中。然后捕获的图​​像应该替换该默认图像。

我想强制使用PhoneGap。我已经看过用于相机的PhoneGap API,但我不知道如何使用它。我正在使用Mac和Xcode进行开发。

2 个答案:

答案 0 :(得分:0)

在我的应用程序中使用sencha touch 2和Phonegap 1.4 在控制器中 拍摄照片按钮处理程序

onTakePhotoButton: function(){
       // Retrieve image file location from specified source
        navigator.camera.getPicture(uploadPhoto, function (message) {
            alert('Get picture failed');
        }, {
            quality: 50,
            destinationType: navigator.camera.DestinationType.FILE_URI,
            sourceType: navigator.camera.PictureSourceType.CAMERA //or PHOTOLIBRARY
        }
        );
        function uploadPhoto(imageURI) {
            var options = new FileUploadOptions();
            options.fileKey = "file";
            var imagefilename = Number(new Date()) + ".jpg";
            options.fileName = imagefilename;
            options.mimeType = "image/jpeg";
            options.chunkedMode = false;
            var params = new Object();
            params.image = imagefilename;
            options.params = params;
            var ft = new FileTransfer();
            ft.upload(imageURI,your_request_upload_url_on_server, win, fail, options);
        }

        function win(r) {
            console.log("Code = " + r.responseCode);
            console.log("Response = " + r.response);
            console.log("Sent = " + r.bytesSent);
            var json_obj = Ext.decode(r.response);//remote server funciton upload return json type
            if(json_obj!=null && json_obj.response.image_name!=null){
                console.log(json_obj.response.image_name);
                imageDisplay.setSrc(your_image_root_tmp+json_obj.response.image_name+'?dc='+Number(new Date()));
            }else{
                Ext.Msg.alert('Errors', "The server response failure!");
            }            

        }

        function fail(error) {
            alert("An error has occurred: Code = " + error.code);
        }  
}

您可以在http://zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegap

中详细了解更多详情

答案 1 :(得分:0)

capturePhoto:函数(){

       navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });

       function onPhotoDataSuccess(imageData) {
       // Uncomment to view the base64 encoded image data
       // console.log(imageData);

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

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

       // Show the captured photo
       // The inline CSS rules are used to resize the image
       //
       smallImage.src = "data:image/jpeg;base64," + imageData;        

plz验证......