0

我在 Sencha Touch 2 中开发了一个应用程序。我想设计一个页面,使页面有一个默认图像和一个按钮。通过单击该按钮,设备相机应该打开(设备主要是 iPad 和 iPhone),并在捕获图像后让我们看到它存储在设备中名为“捕获”的文件夹中。然后捕获的图​​像应替换该默认图像。

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

4

2 回答 2

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

于 2012-10-03T09:31:20.210 回答
0

捕获照片:函数(){

       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;        

请验证...

于 2012-10-04T07:11:11.963 回答