2013-02-18 15 views
14

मैं फोनगैप के लिए काफी नया हूं और कहता है कि इसमें कैप्चर फीचर है। तो मैंने इसका इस्तेमाल किया और बहुत अच्छा था। हालांकि मैंने एचटीएमएल में तस्वीर प्रदर्शित की लेकिन मुझे नहीं पता कि छवि को कैसे सहेजना है।स्थानीय स्टोरेज फोनगैप में छवि सहेजें

http://docs.phonegap.com/en/1.7.0/cordova_camera_camera.md.html

आप क्या कर सकते हैं जो कुछ भी आप इनकोडिंग छवि या यूआरआई के साथ चाहते हैं के अनुसार

, उदाहरण के लिए:

एक टैग में मौजूद चित्र प्रस्तुत (नीचे उदाहरण देखें) सहेजें डेटा स्थानीय रूप से (LocalStorage , Lawnchair, आदि) पोस्ट एक दूरस्थ सर्वर

करने के लिए डेटा दुर्भाग्य से इसे कैसे करना

पर कोई नमूना कोड था

मैं स्थानीय स्टोरेज या डिवाइस की गैलरी में छवि कैसे सहेजूं?

+1

पाया गया https://github.com/raananw/PhoneGap-Image-Resizer यह अभी भी काम करता है? – jhdj

+0

यह काम करता है केवल कुछ tweaks – jhdj

उत्तर

22

ग्रेट आपको समाधान मिला, मैंने इसे निम्न तरीके से किया। उम्मीद है कि यह किसी और की मदद करता है।

बस कॉल करें कैप्चर फोटो बटन क्लिक ईवेंट पर फ़ंक्शन।

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

क्या इस कोड को करता है पर डिवाइस के एसडी कार्ड

कैप्चर छवि और यह MyAppFolder में भंडार है। और छविपाथ सत्र में स्थानीय डेटाबेस में डालने के लिए स्टोर करता है।

+2

यह मेरे लिए काम नहीं करता है। क्या आपके पास एक कामकाजी प्रति है। – surhidamatya

+0

धन्यवाद यह मेरे लिए काम करता है। :) – mohitum

+0

मैं छवि पर कब्जा कर सकता था लेकिन स्थानीय भंडारण में सहेजने में विफल रहा –

9

अच्छी तरह से सही कामों के विकल्पों में saveToPhotoAlbum को भी सेट करना। यह 2.9 डॉक्स here से मिला।

+1

दस्तावेज़ों से सरल सलाह के लिए अतिरिक्त अंक। – leech

संबंधित मुद्दे