Phonegap - android - 如果方向设置为真,则图像保存在缓存中

Phonegap - android - image saved in cache if orientation set to true

在设置 correctOrientation : true 时,图像旋转问题得到解决并设置了缩略图 - 但图像路径为:file://storage/emulated/0/Android/data/com.examole.helloworld/modified.jpg?149028394994

没有correctOrientation: true,图片路径为:file:///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
 });

提前致谢。

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

抱歉,您想将此代码与那个一起添加。

我已经解决了这个问题并发布了我的答案

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 中设置了路径本身。

这是一个更好的解决方案(涉及挖掘一些 Java 文件,但大约需要 8 秒)

在 CameraLauncher.java 中(在 cordova-plugin-camera/src/android 文件夹中)

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

也就是将文件名中的时间戳上移。

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