我在iPhone上正确定位图像时遇到了问题。我使用AssetLibrary类访问图像。
我想做的就是正确地定位图像以供显示,不幸的是,对于一些在肖像模式下拍摄的图像,它们是在一个没有意义的方向上。
在框架调用的块中,我调用了iPhone摄像机在其定向“向上”时拍摄的图片,如下所示:
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,它所做的只是初始化图像,设置方向,但不正确地旋转图像。
这似乎是不确定的,为什么这些调用返回不同的结果:
ALAssetOrientation orient = [representation orientation];
ALAssetOrientation alorient = [[myasset valueForProperty:@"ALAssetOrientation"] intValue];你的帮助将不胜感激。
谢谢,威尔
发布于 2013-01-29 08:22:20
问题是您使用了错误的属性名。
在您的代码中:
[[myasset valueForProperty:@"ALAssetOrientation"] intValue];应:
[[myasset valueForProperty:@"ALAssetPropertyOrientation"] intValue];根据文档 of -[ALAsset valueForProperty:]
如果属性不是有效密钥,则返回ALErrorInvalidProperty。
您的代码试图将ALErrorInvalidProperty转换为int,这将导致0。巧合的是,ALAssetOrientationUp的值为0,这就是为什么您的alorient变量总是计算为ALAssetOrientationUp的原因。
https://stackoverflow.com/questions/9830727
复制相似问题