Quantcast
Channel: Foren
Viewing all articles
Browse latest Browse all 170

Unable to save the captured image with unique names

0
0

Hi, 

I am trying to capturing images and save it in a seperate directory in sd card but the image captured gets saved in test.jpg even if i capture new image it saves in the same name.I could not find where the problem is as well as the image is not stored in the created directory.Here is the codes

<!DOCTYPE html><html><head><title>Blank Hybrid App Project Template</title><meta http-equiv="Content-type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"><style>
        @-ms-viewport { width: 100vw ; zoom: 100% ; }
        @viewport { width: 100vw ; zoom: 100% ; }
        @-ms-viewport { user-zoom: fixed ; }
        @viewport { user-zoom: fixed ; }</style><script src="lib/ft/fastclick.js"></script><link rel="stylesheet" href="css/app.css"></head><body>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img  src="" id="picture" width="300" height="300"/><br><br>     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<progress min="0" max="100" width="600" id="progress"></progress><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="captureCamera();">Take a Picture</button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="deleteImage();">Delete Images</button>&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="displayimage();">DisplayImage</button><script src="intelxdk.js"></script><script src="cordova.js"></script><script src="xhr.js"></script><script src="js/app.js"></script><script src="js/init-app.js"></script><script src="js/init-dev.js"></script><script>
        document.addEventListener("deviceready", onDeviceReady, false);
        function onDeviceReady()
        {
            //PERSISTENT indicates that any change we make to the file system now will be permanent.
            requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, onError);
        }
        //fileSystem object points to the hard disk.
        function onSuccess(fileSystem)
        {
            //fileSystem.root points to the application storage directory
            var directoryEntry = fileSystem.root;

            //absolute fileSystem path to the application storage directory
            console.log(directoryEntry.fullPath);

            //web path(or URL) to the application storage directory
            console.log(directoryEntry.toURL());

            //lets create a file named readme.txt. getFile method actually creates a file and returns a pointer(FileEntry) if it doesn't                   exist otherwise just returns a pointer to it. It returns the file pointer as callback parameter.
            directoryEntry.getFile("nidhin.txt", {create: true, exclusive: false}, function(fileEntry){
                //lets write something into the file
                fileEntry.createWriter(function(writer){
                    writer.write("This is the sampletext inside readme file");
                }, function(error){
                    console.log("Error occurred while writing to file. Error code is: " + error.code);
                });

                //lets read the content of the file.
                fileEntry.file(function(file){
                    var reader = new FileReader();
                    reader.onloadend = function (evt) {
                        //result property is string type if you read data as string. If you read data as array buffer then its assigned to a                           array buffer object.
                        console.log(evt.target.result);
                    };
                    //to read the content as binary use readAsArrayBuffer function.
                    reader.readAsText(file);
                }, function(error){
                    console.log("Error occurred while readline file. Error code is: " + error.code);
                });

            }, function(error){
                console.log("Error occurred while getting a pointer to file. Error code is: " + error.code);
            });

            //create a directory using getDirectory. If already exists it returns a pointer only.
            directoryEntry.getDirectory("JCGIntel", {create: true, exclusive: false}, function(directoryEntry_1){
                //for any operation inside this directory use directoryEntry_1 object.
            }, function(error){
                console.log("Error occurred while getting pointer to new directory. Error code is: " + error.code);
            });

            //object to read the contents of the directory
            var directoryReader = directoryEntry.createReader();

            //now read the contents using the readEntries function.
            directoryReader.readEntries(function(entries){
                var i;
                for (i=0; i<entries.length; i++)
                {
                    console.log(entries[i].name);
                }
            },function(error){
                console.log("Failed to list directory contents. Error code is: " + error.code);
            });
        }

        function onError(evt)
        {
            console.log("Error occurred during request to file system pointer. Error code is: " + evt.code);
        }function captureCamera()
        {
            intel.xdk.camera.takePicture(10,true,"jpg");

        }

        function importLibrary()
        {
            intel.xdk.camera.importPicture();
        }
        function displayImage(){
        var arrPictureList = intel.xdk.camera.getPictureList();
        for (var x=0;x<arrPictureList.length;x++)
        {
         var name = arrPictureList[x];
         var url = intel.xdk.camera.getPictureURL(name);
        }
        }
        function deleteImage()
        {
            var arrPictureList = intel.xdk.camera.getPictureList();
            for (var x=0;x<arrPictureList.length;x++)
            {
             var name = arrPictureList[x];
            //this function is used to delete a image file.
            intel.xdk.camera.deletePicture(name);
            }

            //this is fired after every attempt to delete an image.
            document.addEventListener("intel.xdk.camera.picture.remove",onRemove);

            function onRemove(evt)
            {
              if(evt.success==true)
              {
                 alert(evt.filename + " has been removed from the application storage");
              }
        else
         {
        alert(evt.filename + " has been failed to remove from application storage");
        }
        }
        }
        document.addEventListener("intel.xdk.camera.picture.add",function(event){
            var name = event.filename;
            var url = intel.xdk.camera.getPictureURL(name);
            document.getElementById("picture").setAttribute("src", url);
            //intel.xdk.file.uploadToServer(url,"http://labs.qnimate.com/demo/index.php", "", "image/jpg", "updateUploadProgress");
            intel.xdk.file.uploadToServer(url,"http://nidhinkumar06-001-      site1.1tempurl.com/upload.php","nidhin","image/jpg","updateUploadProgress");
        });


        document.addEventListener("intel.xdk.camera.picture.busy",function(){
            alert("Camera is already in use");
        });
        document.addEventListener("intel.xdk.camera.picture.cancel",function(){
            alert("You pressed the cancel button");
        });
        function updateUploadProgress(bytesSent,totalBytes)
        {
           if(totalBytes>0)
                currentProgress=(bytesSent/totalBytes)*100;
            document.getElementById("progress").setAttribute("value", currentProgress);
        }
        document.addEventListener("intel.xdk.file.upload.busy",uploadBusy);
        document.addEventListener("intel.xdk.file.upload",uploadComplete);
        document.addEventListener("intel.xdk.file.upload.cancel",uploadCancelled);
        function uploadBusy(evt)
        {
           alert("Sorry, a file is already being uploaded");
        }

        function uploadComplete(evt)
        {
           if(evt.success==true)
           {
              alert("File "+evt.localURL+" was uploaded");
           }
           else {
              alert("Error uploading file "+evt.message);
           }
        }
        function uploadCancelled(evt)
        {
            alert("File upload was cancelled "+evt.localURL);
        }</script></body></html>

 


Viewing all articles
Browse latest Browse all 170

Latest Images

Trending Articles





Latest Images