【问题标题】:Phonegap - android - image saved in cache if orientation set to truePhonegap - android - 如果方向设置为 true,则图像保存在缓存中
【发布时间】:2015-05-28 17:08:10
【问题描述】:

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

如果没有correctOrientation: true,图片路径为:file:///storage/emulated/0/DCIM/Camera/1490345556009.jpg

当尝试使用正确的方向设置另一个图像时: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
 });

提前致谢。

【问题讨论】:

  • 对于那些后来发现这个问题的人,这个问题现在已经在最新版本的 cordova-plugin-camera 中得到了解决。升级插件以解决此问题。

标签: android image cordova caching orientation


【解决方案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); } 

【讨论】:

  • 谢谢桑。但这不起作用。我需要从画廊中挑选,所以我使用 sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

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

    在 CameraLauncher.java 中(在 cordova-plugin-camera/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);
    

    【讨论】:

      【解决方案4】:
      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;
          }
      

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

      【讨论】:

        猜你喜欢
        • 2015-11-21
        • 1970-01-01
        • 2016-04-05
        • 2021-11-15
        • 2014-09-07
        • 2016-12-23
        • 2019-04-08
        • 1970-01-01
        • 2013-07-14
        相关资源
        最近更新 更多