我从iPhone/iPad图库加载照片,其中大多数是竖向模式,我想知道如何检查照片是横向还是竖向模式?
UIImage
实例的imageOrientation
属性。它将返回以下常量之一。
示例:
UIImage *image = // 从库中加载
if (image.imageOrientation == UIImageOrientationUp) {
NSLog(@"portrait");
} else if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
NSLog(@"landscape");
}
if (image.imageOrientation == UIImageOrientationUp ||
image.imageOrientation == UIImageOrientationDown )
{
NSLog(@"Image is in Landscape Fix it to portrait ....");
backgroundView.frame = self.view.bounds;
backgroundView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
backgroundView.contentMode = UIViewContentModeScaleAspectFill;
}
else
{
NSLog(@"Image is in Portrait everything is fine ...");
}
这里有一个绝对可靠的方法来进行此检查
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
// Get the data for the image
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
if ([UIImage imageWithData:imageData].size.width > [UIImage imageWithData:imageData].size.height)
{
NSLog(@"Select Image is in Landscape Mode ....");
}
else
{
NSLog(@"Select Image is in Portrait Mode ...");
}
}