Iphone 如何知道照片是横向模式还是纵向模式?
我从iPhone/iPad库中加载照片,大多数是在纵向模式下,我想知道如何在横向或纵向模式下检查照片?使用Iphone 如何知道照片是横向模式还是纵向模式?,iphone,ipad,photo,Iphone,Ipad,Photo,我从iPhone/iPad库中加载照片,大多数是在纵向模式下,我想知道如何在横向或纵向模式下检查照片?使用UIImage实例的imageOrientation属性。它将返回一个常量 例如: UIImage*image=//从库中加载 if (image.imageOrientation == UIImageOrientationUp) { NSLog(@"portrait"); } else if (image.imageOrientation == UIImageOrientation
UIImage
实例的imageOrientation
属性。它将返回一个常量
例如:
UIImage*image=//从库中加载
if (image.imageOrientation == UIImageOrientationUp) {
NSLog(@"portrait");
} else if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
NSLog(@"landscape");
}
我在运行iOS 5.0的iPhone4上测试了几十张实际图片,并成功地使它们都处于纵向模式。这就是您修复/检查的方式
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 ...");
}
}
您想知道设备或照片的方向吗?您可以使用Viren的答案获得当前设备的方向。否则,比较照片的高度和宽度,得到其纵横比。但是没有办法知道实际的方向。这帮助我开始选择相册,我想为拍照添加一些补充信息,我没有意识到这是两件完全不同的事情!当用户使用iPhone的照相机拍摄快照时,图像不是垂直的,而是逆时针旋转90度。因此,如果您想在
NSLog(@“纵向”)的if
块中结束
然后您将测试UIImageOrientationLeft | | UIImageOrientationRight | | UIImageOrientationLeftMirrored | | uiimageorientationrightmrrored
,其余将是横向