如何显示科尔多瓦相机拍摄的图像? (Xcode中/ iOS的)

时间:2013-08-06 05:51:35

标签: iphone ios xcode cordova

我可以访问相机甚至远程保存图像,但我想在上传之前在屏幕上显示图像。

打开设备摄像头的功能是:

function capturePhoto() {
                    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 10, width: 412, height: 412, correctOrientation: 1, saveToPhotoAlbum: 1});
                }

最初拍摄照片后触发的功能是:

  function uploadImage() {
                imageURI = lastImage;

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

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


                var fail, ft, options, params, win;

                // callback for when the photo has been successfully uploaded:
                var success =  function(response) {
                    //alert(tags);
                    alert("Photo Saved");
                };

                // callback if the photo fails to upload successfully.
                var fail = function(error) {
                    alert("An error has occurred: Code = " + error.code);
                    alert(FileTransferError.CONNECTION_ERR);
                };
                 //FILE UPLOAD SCRIPTS
                options = new FileUploadOptions();
                options.fileKey = "my_image";
                options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
                options.mimeType = "text/plain";
                params = {
                    val1: tags,
                    val2: location
                };
                options.params = params;
                ft = new FileTransfer();
                ft.upload(imageURI, 'http://mysite.com/recieve.php', success, fail, options);

            }

要显示图像的HTML:

     <img style="display :none;width:60px;height:60px;" id="smallImage" src="" />

我假设线路有问题

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

但我不确定是什么或如何解决它。

有人知道如何修改这个吗?

1 个答案:

答案 0 :(得分:0)

我明白了。

我改变了行

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

也是

 smallImage.src = imageURI;