2012-02-01 75 views
0

我想从UIImagePickerController中选择一张照片,并检查照片是否为横向。如果选择的照片是横向的,我想旋转到纵向。 所以,这里是我的代码UIImageOrientationRight(左)将不起作用

- (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:]方法是工作的罚款。只是卡住了为什么它不识别风景照片。帮我!

回答

2

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

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

if(image.size.width > image.size.height) 
    UIImage *retatedImg = [image imageRotatedByDegrees:90] ; 
+0

谢谢!现在我明白了 – user842589 2012-02-01 11:40:36