2013-02-18 126 views
0

我正在使用phonegap開發IOS應用程序...我使用了默認攝像機API,因此用戶可以爲其用戶個人資料圖片拍照。捕獲手機後保存圖像ios

功能工作正常,但我的問題的圖像,用戶捕捉它不會保存在系統上的文件,所以我可以在

這裏其他的網頁檢索它是我的代碼

var pictureSource; // picture source 
    var destinationType; // sets the format of returned value 

    // Wait for Cordova to connect with the device 
    // 
    document.addEventListener("deviceready",onDeviceReady,false); 

    // Cordova is ready to be used! 
    // 
    function onDeviceReady() { 
     pictureSource=navigator.camera.PictureSourceType; 
     destinationType=navigator.camera.DestinationType; 
    } 

    // Called when a photo is successfully retrieved 
    // 
    function onPhotoDataSuccess(imageData) { 
     // Uncomment to view the base64 encoded image data 
     // console.log(imageData); 

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

     // Unhide image elements 
     // 
     smallImage.style.display = 'block'; 

     // Show the captured photo 
     // The inline CSS rules are used to resize the image 
     // 
     smallImage.src = "data:image/jpeg;base64," + imageData; 

    } 

    // Called when a photo is successfully retrieved 
    // 
    function onPhotoURISuccess(imageURI) { 
     // Uncomment to view the image file URI 
     // console.log(imageURI); 

     // Get image handle 
     // 
     document.getElementById('smallImage').src='img/me2.jpg'; 
     var smallImage = 'img/me2.jpg'; 

     // Unhide image elements 
     // 
     smallImage.style.display = 'block'; 

     // Show the captured photo 
     // The inline CSS rules are used to resize the image 
     // 
     smallImage.src = imageURI; 
    } 

    // A button will call this function 
    // 
    function capturePhoto() { 
     // Take picture using device camera and retrieve image as base64-encoded string 
     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, 
     destinationType: destinationType.DATA_URL }); 
    } 

    // A button will call this function 
    // 
    function capturePhotoEdit() { 
     // Take picture using device camera, allow edit, and retrieve image as base64-encoded string 
     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, allowEdit: true, 
     destinationType: destinationType.DATA_URL }); 
    } 

    // A button will call this function 
    // 
    function getPhoto(source) { 
     // Retrieve image file location from specified source 
     navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
     destinationType: destinationType.FILE_URI, 
     sourceType: source }); 
    } 

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

我怎麼可以在用戶使用相機拍攝照片後覆蓋文件(「img/me2.jpg」)?

回答

1

由於該文件位於應用程序包中,因此無法覆蓋img/me2.jpg。

您必須將捕獲的圖像保存在應用程序數據文件夾中(例如,使用PhoneGap的File API),然後將url保存在localStorage中,您可以隨時從中檢索它。