Javascript iPhone 5在PhoneGap中的摄像头功能,图像压缩

Javascript iPhone 5在PhoneGap中的摄像头功能,图像压缩,javascript,cordova,ios6,iphone-5,Javascript,Cordova,Ios6,Iphone 5,所以我有一个ios应用程序,在ios6/iPhone5之前。它工作得很好。我目前正在尝试为iPhone5和ios6修复它。进行得很顺利,我已经解决了ios6 99%的bug,而且似乎很有效。然而,iphone5却喜怒无常 我正在使用PhoneGap 1.8.1。在某一点上,我使用此功能使用相机拍摄图像: function capturePhoto() { networkState = navigator.network.connection.type;

所以我有一个ios应用程序,在ios6/iPhone5之前。它工作得很好。我目前正在尝试为iPhone5和ios6修复它。进行得很顺利,我已经解决了ios6 99%的bug,而且似乎很有效。然而,iphone5却喜怒无常

我正在使用PhoneGap 1.8.1。在某一点上,我使用此功能使用相机拍摄图像:

function capturePhoto() {

        networkState = navigator.network.connection.type; 

            if (networkState == Connection.NONE)
                {
                  alert('You must be connected to the internet to use this feature!');

                }else{


                var options = {
                    quality: 100,
                    correctOrientation: false,
                    destinationType : navigator.camera.DestinationType.FILE_URI,
                    sourceType: navigator.camera.PictureSourceType.CAMERA,
                    encodingType: navigator.camera.EncodingType.JPEG,
              }
          navigator.camera.getPicture(onPhotoDataSuccess, onFail, options);

    }
}
targetWidth: 320,
targetHeight: 480,
然后,我将图像显示为HTML画布上的背景。使用kineticJS但出于这个问题的目的,我认为您需要知道的是:

var canvaswidth = window.innerWidth;
var canvasheight = window.innerHeight;

var darthVaderImg = new Kinetic.Image({
                                          x: 0,
                                          y: 0,
                                          image: images.darthVader,
                                          width: canvaswidth,
                                          height: canvasheight,
                                          name: "image"
                                          });
这个在iPhone4S ios 6上运行很好,这个在android上运行很好。。。但在iPhone5上却没有。图片的方向是正确的,但是它在顶部被压扁了,我努力把它编码成iPhone5的屏幕大小。。。。我相信是640x1136


还是不走运,比如说,如果我放大并将图像高度设置为2000,它确实会覆盖屏幕,但会放大。我有点不知道发生了什么事。。。。有人有过类似的问题或想法吗?

好的,我想我已经解决了这个问题:

首先要意识到的是,iPhone5拍摄的照片与iPhone4S拍摄的照片大小完全相同。我刚刚测试并确认了这一点。因此,额外的屏幕大小是无关紧要的

当我意识到这一点时,我使用了西蒙·麦克唐纳的一篇文章。可从以下网址获得:

然后,我在capturePhoto函数中添加了以下两行:

function capturePhoto() {

        networkState = navigator.network.connection.type; 

            if (networkState == Connection.NONE)
                {
                  alert('You must be connected to the internet to use this feature!');

                }else{


                var options = {
                    quality: 100,
                    correctOrientation: false,
                    destinationType : navigator.camera.DestinationType.FILE_URI,
                    sourceType: navigator.camera.PictureSourceType.CAMERA,
                    encodingType: navigator.camera.EncodingType.JPEG,
              }
          navigator.camera.getPicture(onPhotoDataSuccess, onFail, options);

    }
}
targetWidth: 320,
targetHeight: 480,
这确保了拍摄的图像大小正确,另外的优点是在4和5上的图像大小正确

然后我确保它以正确的大小显示在画布上,我的画布显示大小为:

var canvaswidth = 320;
var canvasheight = 480;

var darthVaderImg = new Kinetic.Image({
                                          x: 0,
                                          y: 0,
                                          image: images.darthVader,
                                          width: canvaswidth,
                                          height: canvasheight,
                                          name: "image"
                                          });
这样可以保持图像的比例,我身上的完美主义者说它只有99%的正确率,但它覆盖了画布,并没有不成比例

这确实让我在iPhone 5上留下了过多的“空间”,但我只是通过检测窗口高度用IF语句来解决这个问题:

window.innerHeight
使用这个变量,我可以区分iphone5和iphone4/4s,然后我可以为两者设置不同的规则,直到显示动作

希望这能帮助任何遇到同样问题的人