Objective c 使用ALAssetOrientation和UIImageOrientation确定正确方向时出现的问题

Objective c 使用ALAssetOrientation和UIImageOrientation确定正确方向时出现的问题,objective-c,uiimage,orientation,alasset,uiimageorientation,Objective C,Uiimage,Orientation,Alasset,Uiimageorientation,我在iPhone上无法正确定位图像。我正在使用AssetLibrary类访问图像 我想做的就是正确地确定图像的显示方向,不幸的是,对于一些在纵向模式下拍摄的图像,它们的方向没有意义 在框架调用的块中,我调用了一张iPhone摄像头在“向上”时拍摄的照片,如下所示: ALAssetRepresentation *representation = [myasset defaultRepresentation]; ALAssetOrientation or

我在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:orientation:重载实例化timg,使用orientation作为orientation参数,它所做的只是初始化图像设置方向,但错误地旋转图像

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

ALAssetOrientation      orient   = [representation orientation];
ALAssetOrientation      alorient = [[myasset valueForProperty:@"ALAssetOrientation"] intValue];
非常感谢你的帮助

谢谢,
Will

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

在代码中:

[[myasset valueForProperty:@"ALAssetOrientation"] intValue];
应该是:

[[myasset valueForProperty:@"ALAssetPropertyOrientation"] intValue];

根据
-[ALAsset valueForProperty:][/code>


您的代码尝试将
ALErrorInvalidProperty
强制转换为int,这将导致
0
。巧合的是,
ALASSETORIENTIONUP
的值为
0
,这就是为什么
alorient
变量总是计算为
ALASSETORIENTIONUP

严重的是,没有人对此发表评论?!!?
If property is not a valid key, returns ALErrorInvalidProperty.