简体   繁体   中英

How to show image taken from camera in Cordova? (Xcode/iOS)

I am able to access the camera and even save the image remotely, but I would like to show the image on the screen before I upload.

The function that opens the devices camera is:

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

The function that is triggered after the photo is initially taken is:

  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);

            }

And the HTML where the image is to be displayed:

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

I am assuming there is something wrong with the line

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

but I am not sure what or how to fix it.

Would anyone know how to ammend this?

I got it.

I changed the line

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

too

 smallImage.src = imageURI;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM