UIImagePickerController图像方向

任何人都可以告诉我如何使用UIImagePickerController(相机和相册)代表确定图像的方向,相应地旋转,并将其分配给UIImageView?     
已邀请:
不,UIImagePickerController无法显式执行。 如果要根据图像的内容确定。这是一个很难的问题。如何在不了解图像内容的情况下确定图像的方向? 我可以建议你一个技巧,你检查返回图像的宽度和长度,看看它是纵向还是横向。为了旋转图像,外面有一些库和代码,但我没有尝试过多少。你可以看看这个博客     
Vodkhang的答案部分不正确 - 现代相机拍摄照片时会在图像中显示明确的方向。这已经普遍存在了大约5年多。 我之前使用过这个答案中的代码通过直接从图片中读取“方向”信息来进行旋转: UIImagePickerController相机预览是风景应用中的肖像     
    // Use this UIImagePickerController's  delegate method
    - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
        // Getting image user just has shoot
        UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];

        // Fixing to stick with only one orientation (UIImageOrientationUp in this case)
        switch (image.imageOrientation) {
            case UIImageOrientationDown:
            case UIImageOrientationDownMirrored:
            case UIImageOrientationLeft:
            case UIImageOrientationLeftMirrored:
            case UIImageOrientationRight:
            case UIImageOrientationRightMirrored:
                image = [UIImage imageWithCGImage:image.CGImage
                                                  scale:image.scale
                                            orientation:UIImageOrientationUp]; // change this if you need another orientation
                break;
            case UIImageOrientationUp:
            case UIImageOrientationUpMirrored:
                // The image is already in correct orientation
                break;
        }

        // Do whatever you want with image (likely pass it to some UIImageView to display)
        UIImageView *imgView = [[UIImageView alloc] initWithImage:image];

        // Dismiss UIImagePickerController
        [picker dismissModalViewControllerAnimated:NO];
    }
注意:
UIImageView
读取
imageOrientation
属性并相应显示
UIImage
。     

要回复问题请先登录注册