如何知道照片是横向还是纵向模式?

发布于 2024-10-15 07:09:49 字数 59 浏览 1 评论 0 原文

我从 iPhone/iPad 库中加载照片,大部分都是纵向模式,我想知道如何查看横向或纵向模式下的照片?

I load photo from iPhone/iPad library, most of them in Portrait mode, I want to know How can I check the photo in Landscape or Portrait mode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱格式化 2024-10-22 07:09:49

使用 UIImage 实例的 imageOrientation 属性。它将返回您之一 这些常量。

示例:

UIImage *image = // 从库加载

if (image.imageOrientation == UIImageOrientationUp) {
    NSLog(@"portrait");
} else if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
    NSLog(@"landscape");
}

Use the imageOrientation property of UIImage instances. It is going to return you one of these constants.

Example:

UIImage *image = // loaded from library

if (image.imageOrientation == UIImageOrientationUp) {
    NSLog(@"portrait");
} else if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
    NSLog(@"landscape");
}
悲念泪 2024-10-22 07:09:49

我在运行 iOS 5.0 的 iPhone 4 上的数十张实际图片上测试了这段代码,并成功地将它们全部设为纵向模式。这就是修复/检查的方法

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 ...");

    }
}

I tested this piece of code on tens of actual picture on iPhone 4 running iOS 5.0 and was able to successfully make them all in portrait mode. This is how you fix/check

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 ...");
    }

Here is a fool proof way of doing this check

-(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 ...");

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文