【发布时间】:2015-01-13 04:56:02
【问题描述】:
当我在人像模式下使用手机拍照时,使用 UIImagePickerController,返回的 UIImage 项的图像顶部朝左,imageOrientation 属性为UIImageOrientationRight , // 90 deg CCW,这与预期的一样(我认为) .
当我通过 UIActivityViewController 共享图像时,所有活动似乎都正常运行,除了 Copy 活动。当我将图像粘贴到另一个应用程序(例如 Messages)时,图像似乎忽略了 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)并选择消息、保存图像等分享活动,图像方向正确。如果您选择复制活动,则粘贴到别处的图像会旋转(图像的顶部在左侧)。
以Radar 19456881 提交。完整的项目可用here。
【问题讨论】:
标签: ios uiimage uiactivityviewcontroller uiimageorientation