ios - 从 Ipad 捕获的照片将在服务器上反转

标签 ios ipad cordova

我正在 phonegap 中开发一个应用程序并具有使用 Ipad 相机拍摄照片的功能,它可以正常工作并且所有照片都正确保存在服务器上。唯一的问题是它们在服务器上保存时向左旋转了 90 度。

现在我对存储在库中的照片尝试了同样的操作,并且它们是在服务器上上传的,所以我认为问题出在 ipad 照片捕获过程上。谁能帮我找到解决此类问题的方法。这是 Ipad 的正常行为还是我在代码中弄错了?

我已经使用下面的功能来实现照片功能

//Capture Photo either from camera or IPAD library
   function capturePhoto(source){

    var deferred = $q.defer();
    //When source == 1 than from Photo Library
    var cameraOptions = { quality: 70, destinationType: Camera.DestinationType.FILE_URI };
    if(source == 1){ cameraOptions = { quality: 70, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,targetWidth: 600,targetHeight: 600 }; }

    navigator.camera.getPicture( function (imageURI) {
        window.resolveLocalFileSystemURI(imageURI, function (fileEntry) {

            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {

                  fileSys.root.getDirectory("auditPhotos", {create: true, exclusive: false}, function(dir) {

                      fileEntry.copyTo(dir,generateRandomID()+".jpg",function (entry) {
                                       deferred.resolve(entry.fullPath)
                      }, null);
                  }, null);
            }, null);
        },null);
      },
      function (message)  {
        deferred.reject(message);
      },
      cameraOptions
    );
    //deferred.resolve(generateRandomID()+".jpg");
    return deferred.promise;
  }

最佳答案

当您以 jpg 格式在服务器上保存捕获的图像(使用上述功能)时。 JPG 和 JPEG 具有存储图像方向的 EXIF 属性。当您通过 IPAD 拍摄图像时,此 exif 数据存储相机方向和其他与位置相关的内容。但这只能被 ipad 而不是浏览器理解,这就是为什么在浏览器中看到图像旋转的原因,这是事实。当您在 IPAD 中查看时,由于 EXIF 的可用性,它被 IPAD 设置在正确的位置。

要解决此问题,只需将图像保存为 PNG 格式而不是 JPG 即可,一切正常:-)

关于ios - 从 Ipad 捕获的照片将在服务器上反转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25917233/

相关文章:

javascript - ionic 2 : Run functions while scrolling on iOS

ios - 正则表达式从字符串中获取字符串

ios - 不正确的 Popover 大小 - 在 Popover 中的 Navigation Controller 下显示 UITableViews 时

html - Phonegap JQTouch 多页表单 - 存储信息直到最终 POST

node.js - npm 错误!/usr/bin/git ls-remote -h -t ssh ://git@github. com/node_modules/cordova.git

iphone - 在 tableViewCell 中按升序排列值

ios - 将 Int 转换为 CMAttachmentMode

iphone - 当出现问题时,我应该如何通知自己(开发人员)?

ipad - 我的纹理密集型游戏应用程序对iPad1的内存之谜

cordova - Sencha Touch 2 和 phonegap - 如何启动应用程序