[英]PhoneGap image rotation issue after transformation
We're developing a PhoneGap app that amongst the core features being developed, it also features a user profile section. 我们正在开发一个PhoneGap应用程序,在正在开发的核心功能中,它还具有用户配置文件部分。 Within that screen/section we allow the user to update various details including their profile image.
在该屏幕/部分内,我们允许用户更新各种细节,包括他们的个人资料图像。 The profile image can either be taken with the camera (which works perfectly) or chosen from the users photo library.
配置文件图像可以与相机一起拍摄(效果很好),也可以从用户照片库中选择。 This is where our issue lies.
这就是我们的问题所在。
We're loading a photo from the users camera or camera roll using the navigator.camera.getPicture
function. 我们正在使用
navigator.camera.getPicture
函数从用户相机或相机胶卷加载照片。
We then create a new Image()
and set the imageURI
returned by phone gap as the image src
. 然后我们创建一个新的
Image()
并将手机间隙返回的imageURI
设置为图像src
。 In the onload
function of the image we draw the image into a canvas context to resize and crop it into a square. 在图像的
onload
函数中,我们将图像绘制到画布上下文中以调整大小并将其裁剪为正方形。
We had a problem with the image, where when rendering the image was squashed but we've fixed that issue with the help of this post ( HTML5 Canvas drawImage ratio bug iOS ) 我们的图像有问题,当渲染图像被压扁但我们已经在这篇文章的帮助下解决了这个问题( HTML5 Canvas drawImage ratio bug iOS )
The Problem: Everything works well when we get the image directly from the camera but when we set destinationType
to navigator.camera.PictureSourceType.SAVEDPHOTOALBUM
or navigator.camera.PictureSourceType.PHOTOLIBRARY
the image comes out rotated incorrectly. 问题:当我们直接从相机获取图像时,一切正常,但是当我们将
destinationType
设置为navigator.camera.PictureSourceType.SAVEDPHOTOALBUM
或navigator.camera.PictureSourceType.PHOTOLIBRARY
,图像旋出不正确。
correctOrientation
is set to true. correctOrientation
设置为true。
We're using Cordova 2.8 我们正在使用Cordova 2.8
We can only get image data when the designationType is FILE_URI
for CAMERA and NATIVE_URI
for PHOTOLIBRARY
. 当
FILE_URI
为CAMERA的NATIVE_URI
和NATIVE_URI
的PHOTOLIBRARY
时,我们只能获取图像数据。 Could this difference have something to do with our problem? 这种差异可能与我们的问题有关吗?
The code is: 代码是:
navigator.camera.getPicture(function (imageURI) {
context = // 2d context from canvas object in the DOM
base_image = new Image();
base_image.onload = function () {
var x = 0;
var y = 0;
var w = 144;
var h = 144;
... // some size and offset calculations
var ratio = ... // calculate a ratio based off this question https://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
context.drawImage(base_image, x, y, base_image.width, base_image.height, 0, 0, w, h/ratio);
url = context.canvas.toDataURL().toString();
DOMImage.src = url
}
base_image.src = imageURI;
}, function (error) {
enyo.log("Error " + error);
}, {
quality : 49,
targetWidth: 114,
targetHeight: 114,
sourceType: sourceType,
encodingType: Camera.EncodingType.JPEG,
destinationType: destinationType,
correctOrientation: true,
saveToPhotoAlbum: false
});
Any advice is much appreciated. 任何建议都非常感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.