我从iPhone/iPad库中加载照片,其中大多数都处于肖像模式,我想知道如何以横向或纵向模式检查照片?如何知道横向或纵向模式下的照片?
8
A
回答
12
使用UIImage
实例的imageOrientation
属性。它会返回你的常量之一these。
实施例:
的UIImage *图像= //从库加载
if (image.imageOrientation == UIImageOrientationUp) {
NSLog(@"portrait");
} else if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
NSLog(@"landscape");
}
+2
这帮助我开始了专辑的选择,并且我想为照片添加一些补充信息,但我没有意识到它们是两个完全不同的东西!当用户使用iPhone的相机拍摄快照时,图像不是直立的,而是实际上逆时针旋转90度。所以,如果你想最终在'NSLog'的'if'块中(@“portrait”);`那么你会测试'UIImageOrientationLeft || UIImageOrientationRight || UIImageOrientationLeftMirrored || UIImageOrientationRightMirrored`和其余的将是`风景` – pulkitsinghal 2012-12-09 15:51:49
1
我测试这段代码上几十实际图像的iPhone 4上运行iOS 5.0和能够成功使它们全部都是纵向模式。这是你如何修复/检查
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 ...");
}
}
相关问题
- 1. 如何知道图片是横向还是纵向?
- 2. 方向纵向和横向模式
- 3. 如何旋转相机预览以拍摄纵向模式下的横向照片?
- 4. 如何在横向模式而不是纵向模式下捕获avfoundation
- 5. 使用片段在横向和纵向模式之间切换
- 6. 从PDF/linux获取pdf的布局模式(横向或纵向)
- 7. 的XCode:如何更改的横向和纵向模式
- 8. 如何检查appdelegate上的横向和纵向模式?
- 9. 蓝牙在纵向/横向模式下断开
- 10. 在横向和纵向模式下使用ScrollViewer正确滚动
- 11. Android相机在纵向和横向模式下保存图像
- 12. 在纵向和横向模式下运行espresso androidTest s
- 13. 在横向和纵向模式下启动iPad应用程序
- 14. 检查WP7中的纵向或横向
- 15. UIDeviceOrientation未知在横向模式下
- 16. 如何将纵向视图更改为横向模式?
- 17. 如何找出纵向或横向的屏幕方向?
- 18. 如何处理Android中的横向或纵向模式启动服务...?
- 19. 如何在Android中检查照片是以横向还是纵向模式拍摄的?
- 20. 如何以横向适应纵向图像在纵横比保持纵横比
- 21. 如何在横向模式或纵向模式下自动更改ADBannerView的尺寸
- 22. UIScrollView在纵向模式和横向模式下的行为不同
- 23. 如何更改纵向和横向的模拟器方向?
- 24. Android:如何处理纵向反转纵向和横向反转横向事件
- 25. 复选框从纵向到横向模式的句柄方向
- 26. 风格嵌入式Instagram照片横向
- 27. 应用程序方向(横向或纵向)如何锁定?
- 28. 如何MediaRecorder方向设置为横向或纵向
- 29. iPhone模拟器横向纵向
- 30. UIDeviceOrientationFaceUp - 如何区分纵向和横向?
做的傻瓜的证明呢?您可以通过Viren的答案获得当前的设备定位。否则,比较照片的高度和宽度以得到其纵横比。但是没有办法知道实际的方向。 – jakev 2011-02-03 00:32:36