UIImageOrientationRight(左)不起作用

时间:2012-02-01 10:15:58

标签: iphone

我想从UIImagePickerController中选择一张照片并检查照片是否为风景照片。如果选择的照片是风景,我想旋转到肖像。 所以,这是我的代码

- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo {

    if(image.imageOrientation == UIImageOrientationRight || image.imageOrientation == UIImageOrientationLeft){

        UIImage *retatedImg = [image imageRotatedByDegrees:90];

    }else {
        UIImage *retatedImg = image;

    }
}

我确定[imageRotatedByDegrees:]方法运行正常。只是坚持为什么它不识别风景照片。帮助我!

1 个答案:

答案 0 :(得分:2)

imageOrientation属性不是指图像的格式。加载图像时,该属性的值取决于文件中的EXIF数据(如果有)。如果拍摄照片的相机以最终格式保存,则不会包含用于图像方向更改的EXIF数据。

如果您想知道该图像格式是纵向还是横向,请比较宽度和高度尺寸,而不是使用imageOrientation。

if( image.size.width > image.size.height ) 
    UIImage *retatedImg = [image imageRotatedByDegrees:90] ;
相关问题