首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用ALAssetOrientation和UIImageOrientation确定正确定位的问题

用ALAssetOrientation和UIImageOrientation确定正确定位的问题
EN

Stack Overflow用户
提问于 2012-03-22 21:19:49
回答 1查看 2.4K关注 0票数 3

我在iPhone上正确定位图像时遇到了问题。我使用AssetLibrary类访问图像。

我想做的就是正确地定位图像以供显示,不幸的是,对于一些在肖像模式下拍摄的图像,它们是在一个没有意义的方向上。

在框架调用的块中,我调用了iPhone摄像机在其定向“向上”时拍摄的图片,如下所示:

代码语言:javascript
复制
        ALAssetRepresentation   *representation = [myasset defaultRepresentation];
        ALAssetOrientation      orient          = [representation orientation];
        ALAssetOrientation      alorient = [[myasset valueForProperty:@"ALAssetOrientation"] intValue];
        UIImage                 *timg           = [[UIImage alloc] initWithCGImage:[representation fullScreenImage]];
        UIImageOrientation      imgorient       = [timg imageOrientation];

THe variable orient = ALAssetOrientationRight.
The variable alorient = ALAssetOrientationUp.
The variable imgorient = UIImageOrientationUp

我使用了方位值来旋转图像,使其看起来“向上”。不幸的是,如果我有一个图像是在景观模式下拍摄的,同样的代码不能工作,因为方向是不正确的。

我尝试过用scale:取向:重载使用方位参数来实例化timg,它所做的只是初始化图像,设置方向,但不正确地旋转图像。

这似乎是不确定的,为什么这些调用返回不同的结果:

代码语言:javascript
复制
ALAssetOrientation      orient   = [representation orientation];
ALAssetOrientation      alorient = [[myasset valueForProperty:@"ALAssetOrientation"] intValue];

你的帮助将不胜感激。

谢谢,威尔

EN

回答 1

Stack Overflow用户

发布于 2013-01-29 08:22:20

问题是您使用了错误的属性名。

在您的代码中:

代码语言:javascript
复制
[[myasset valueForProperty:@"ALAssetOrientation"] intValue];

应:

代码语言:javascript
复制
[[myasset valueForProperty:@"ALAssetPropertyOrientation"] intValue];

根据文档 of -[ALAsset valueForProperty:]

如果属性不是有效密钥,则返回ALErrorInvalidProperty。

您的代码试图将ALErrorInvalidProperty转换为int,这将导致0。巧合的是,ALAssetOrientationUp的值为0,这就是为什么您的alorient变量总是计算为ALAssetOrientationUp的原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9830727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档