2015-03-25 18 views
1

On setting correctOrientation:true,然後解決圖像旋轉問題並設置縮略圖 - 但圖像路徑爲:file:// storage/emulated/0/Android /數據/ com.examole.helloworld/modified.jpg 149028394994Phonegap - android-image如果方向設置爲true,則保存在緩存中

沒有correctOrientation:真實,圖像路徑是:文件:///storage/emulated/0/DCIM/Camera/1490345556009.jpg

嘗試當使用correctOrientation:true設置另一個圖像,則未設置最新選擇的圖像。 以下爲你的善良參考代碼:

navigator.camera.getPicture(captureSuccess, onFail, {quality: 50, 
     destinationType: Camera.DestinationType.FILE_URI, 
     sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM, 
     mediaType: Camera.MediaType.PICTURE, 
     correctOrientation: true, 
     allowEdit: true 
}); 

在此先感謝。

+0

對於那些後來發現這個問題,現在已經在最新版本的cordova-plugin-camera中解決了這個問題。升級插件來解決這個問題。 – KyleT 2016-01-22 00:45:15

回答

1

我已經解決了這個和張貼了我的答案

navigator.camera.getPicture(captureSuccess, onFail, {quality: 50, 
     destinationType: Camera.DestinationType.FILE_URI, 
     sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM, 
     mediaType: Camera.MediaType.PICTURE, 
     correctOrientation: true, 
}); 

var captureSuccess = function(mediaFiles) { 
    var fD = mediaFiles; 
    window.resolveLocalFileSystemURI(fD, function(fileEntry) { 
     fileEntry.file(function(fT) { 
     var fname = fileEntry.nativeURL.substr(fileEntry.nativeURL.lastIndexOf('/') + 1); 
     fileTransferUpload(fD,fname); 
     }, function() { 
     console.log('error'); 
     }); 
    }, onFError); 
}; 

方法fileTransferUpload以上將只設置src中的圖像路徑。

在成功回調函數中,圖像路徑被接收到,並且沒有從這個路徑獲取nativeURL,我已經在src中設置了路徑本身。

1
You can try this,  

    $(document).on('click','.capture_photo',function(){ 
       navigator.camera.getPicture(onPhotoDataSuccess, onFail, { 
        quality : 75, 
        destinationType : Camera.DestinationType.DATA_URL, 
        sourceType : Camera.PictureSourceType.CAMERA, 
        encodingType: Camera.EncodingType.PNG, 
        popoverOptions: CameraPopoverOptions, 
        saveToPhotoAlbum: false 
       }); 
      }); 
     // to call the success function of capture image(onPhotoDataSuccess) 
      function onPhotoDataSuccess(imageData) { 
       sessionStorage.setItem("img_api",imageData); 
       $('#captureimg').attr('src','data:image/jpeg;base64,' + imageData); 
       App.show_toast("Profile image updated successfully!"); 
      } 
     //onfail 
    onFail(message) { alert('Failed because: ' + message); } 
+0

謝謝聖。但是這不起作用。我需要從畫廊中挑選,所以我使用的是sourceType:Camera.PictureSourceType.SAVEDPHOTOALBUM – Esther 2015-03-25 09:36:28

0
document.addEventListener("deviceready",onDeviceReady,false); 
    var pictureSource; // picture source 
    var destinationType; // sets the format of returned value 
    function onDeviceReady() { 
     pictureSource=navigator.camera.PictureSourceType; 
     destinationType=navigator.camera.DestinationType; 
    } 

對不起,您要與沿添加此代碼。

1

這裏有一個更好的解決方案(涉及通過一些Java文件挖的地方,但需要大約8秒)

在CameraLauncher.java(在科爾多瓦 - 插件相機/ src目錄/ android文件夾,)

//Old: 
String modifiedPath = getTempDirectoryPath() + "/modified"+".jpg"; 
this.callbackContext.success("file://" + modifiedPath + "?" + System.currentTimeMillis()); 

AKA只是將文件名中的時間戳記向上移動。

//New:  
String modifiedPath = getTempDirectoryPath() + "/modified"+ System.currentTimeMillis() +".jpg"; 
this.callbackContext.success("file://" + modifiedPath);