[英]UIActivityViewController Copy Ignores imageOrientation
When I take a picture with the phone in Portrait mode, using a UIImagePickerController, the UIImage item that is returned has the top of the image facing left and an imageOrientation property of UIImageOrientationRight , // 90 deg CCW
, which is as expected (I think). 当我使用UIImagePickerController在纵向模式下用手机拍照时,返回的UIImage项的图像顶部朝左,并且UIImageOrientationRight的imageOrientation属性为
UIImageOrientationRight , // 90 deg CCW
,这与预期的一样(我认为)。
When I share the image via a UIActivityViewController, all activities seem to behave correctly except for the Copy activity. 当我通过UIActivityViewController共享图像时,除“复制”活动外,所有活动似乎均正常运行。 When I paste the image into another application (for instance, Messages), the image seems to be ignoring the imageOrientation property.
当我将图像粘贴到另一个应用程序(例如,Messages)中时,该图像似乎忽略了imageOrientation属性。
Has anyone else seen this / found a workaround? 其他人有没有看过这个/找到了解决方法?
Updated with complete code: (project contains storyboard with a single button mapped to self.takeImageButton
and - (IBAction)takeImageAndShare:(id)sender;
) 更新了完整的代码:(项目中的故事板带有映射到
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
If you run this code, take a photo with the phone in Portrait ( .imageOrientation
is 3 = UIImageOrientationRight
) and select share activities like Messages, Save Image, etc., the image orientation is correct. 如果运行此代码,请用手机在Portrait(
.imageOrientation
为3 = UIImageOrientationRight
)中UIImageOrientationRight
然后选择共享活动(如消息,保存图像等),则图像方向正确。 If you select the copy activity, the image that gets pasted elsewhere is rotated (top of the image is to the left). 如果选择复制活动,则旋转粘贴到其他位置的图像(图像的顶部在左侧)。
Submitted as Radar 19456881 . 提交为Radar 19456881 。 Complete project is available here .
完整的项目在这里 。
默认情况下,捕获图像方向的行为是UIImageOrientationRight,必须将捕获图像方向设置为sp
[UIDevice currentDevice].orientation
Based on this post, I decided to create my own copy activity: 根据这篇文章,我决定创建自己的复制活动:
//
// PhotoActivityCopy.m
//
// Created by Jeff Vautin on 1/13/15.
// Copyright (c) 2015 Jeff Vautin. All rights reserved.
//
#import "PhotoActivityCopy.h"
#import "ImageKit.h"
@import MobileCoreServices;
@interface PhotoActivityCopy ()
@property (strong,nonatomic) NSData *imageJPEGData;
@end
@implementation PhotoActivityCopy
NSString *PhotoActivityCopyActivityType = @"com.me.uiactivitytype.copy";
NSString *PhotoActivityCopyActivityTitle = @"Copy";
+ (UIActivityCategory)activityCategory
{
return UIActivityCategoryAction;
}
- (NSString *)activityType
{
return PhotoActivityCopyActivityType;
}
- (NSString *)activityTitle
{
return PhotoActivityCopyActivityTitle;
}
- (UIImage *)activityImage
{
CGSize imageSize;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
imageSize = CGSizeMake(76.0, 76.0);
} else {
imageSize = CGSizeMake(60.0, 60.0);
}
return [ImageKit imageOfIconCopyWithExportSize:imageSize];
}
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
BOOL canPerform = NO;
if ([activityItems count] > 1) {
canPerform = NO;
} else if ([[activityItems firstObject] isKindOfClass:[UIImage class]]) {
canPerform = YES;
}
return canPerform;
}
- (void)prepareWithActivityItems:(NSArray *)activityItems
{
self.imageJPEGData = UIImageJPEGRepresentation(activityItems[0], 1.0);
}
- (void)performActivity
{
[[UIPasteboard generalPasteboard] setData:self.imageJPEGData forPasteboardType:(id)kUTTypeJPEG];
[self activityDidFinish:YES];
}
@end
And then I excluded the native copy activity: 然后我排除了本机复制活动:
PhotoActivityCopy *copyActivity = [[PhotoActivityCopy alloc] init];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[chosenImage] applicationActivities:@[copyActivity]];
activityViewController.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.