我们正在开发一个PhoneGap 应用程序,在开发的核心功能中,它还具有用户配置文件部分。在该屏幕/部分中,我们允许用户更新各种详细信息,包括他们的个人资料图像。个人资料图像可以使用相机拍摄(效果很好),也可以从用户照片库中选择。这就是我们的问题所在。
我们正在使用该navigator.camera.getPicture功能从用户相机或相机胶卷中加载照片。
然后我们创建一个新Image()的并将imageURI电话返回的 gap 设置为 image src。在图像的onload函数中,我们将图像绘制到画布上下文中以调整大小并将其裁剪为正方形。
我们遇到了图像问题,在渲染图像时被压扁,但我们已经在这篇文章的帮助下解决了这个问题(HTML5 Canvas drawImage ratio bug iOS)
问题:当我们直接从相机获取图像时一切正常,但是当我们设置destinationType为navigator.camera.PictureSourceType.SAVEDPHOTOALBUM或navigator.camera.PictureSourceType.PHOTOLIBRARY图像旋转不正确时。
correctOrientation 设置为真。
我们正在使用 Cordova 2.8
FILE_URI当 designationType为 CAMERA 和NATIVE_URIfor时,我们只能获取图像数据PHOTOLIBRARY。这种差异可能与我们的问题有关吗?
代码是:
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
});
非常感谢任何建议。