1

I have this code which should get the base64 of the captured image, then save it as a jpg into the devices SD card, under the foler MyAppFolder. However it wont work and i cannot figure out why

<html>
<head>
<script src=../cordova.js></script>
<script>
// A button will call this function
//
function capturePhoto() {
sessionStorage.removeItem('imagepath');
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI });
}

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

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

    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    imgProfile.src = imageURI;
    if(sessionStorage.isprofileimage==1){
        getLocation();
    }
    movePic(imageURI);
}

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

function movePic(file){ 
window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError); 
} 

//Callback function when the file system uri has been resolved
function resolveOnSuccess(entry){ 
var d = new Date();
var n = d.getTime();
//new file name
var newFileName = n + ".jpg";
var myFolderApp = "MyAppFolder";

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {      
//The folder is created if doesn't exist
fileSys.root.getDirectory( myFolderApp,
                {create:true, exclusive: false},
                function(directory) {
                    entry.moveTo(directory, newFileName,  successMove, resOnError);
                },
                resOnError);
                },
resOnError);
}

//Callback function when the file has been moved successfully - inserting the complete  path
function successMove(entry) {
//Store imagepath in session for future use
// like to store it in database
sessionStorage.setItem('imagepath', entry.fullPath);
}

function resOnError(error) {
alert(error.code);
}
</script>
</head>
<body>

<button onclick="capturePhoto()">Take photo</button>
<img src="" id="imgProfile" style=position:absolute;top:0%;left:0%;width:100%;height:100%;>


</body>
</html>

when the button is pressed, the camera doesnt launch.

Hamzah Malik
  • 273
  • 2
  • 5
  • 13

1 Answers1

-1

The button wont get clicked because your image src is overlapping it. Change the position of image src and your code shall work fine

laaposto
  • 11,835
  • 15
  • 54
  • 71