当我在肖像模式下使用手机拍照时,使用 UIImagePickerController,返回的 UIImage 项具有图像的顶部朝左和 imageOrientation 属性UIImageOrientationRight , // 90 deg CCW
,这是预期的(我认为)。
当我通过 UIActivityViewController 共享图像时,所有活动似乎都正常运行,除了 Copy 活动。当我将图像粘贴到另一个应用程序(例如,消息)时,图像似乎忽略了 imageOrientation 属性。
有没有其他人看到这个/找到了解决方法?
已更新完整代码:(项目包含情节提要,其中一个按钮映射到self.takeImageButton
和- (IBAction)takeImageAndShare:(id)sender;
)
#import "ViewController.h"
@interface ViewController () <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (weak, nonatomic) IBOutlet UIButton *takeImageButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)takeImageAndShare:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.popoverPresentationController.sourceView = self.takeImageButton;
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:NULL];
NSLog(@"Image Orientation: %li",chosenImage.imageOrientation);
// Now share the selected image
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[chosenImage] applicationActivities:nil];
activityViewController.modalPresentationStyle = UIModalPresentationPopover;
activityViewController.popoverPresentationController.sourceView = self.takeImageButton;
[self presentViewController:activityViewController animated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
@end
.imageOrientation
如果您运行此代码,用手机在人像(是 3 = )中拍照UIImageOrientationRight
并选择共享活动,如消息、保存图像等,图像方向是正确的。如果您选择复制活动,则粘贴到别处的图像会旋转(图像顶部在左侧)。
作为雷达 19456881提交。完整的项目可在此处获得。