为什么 UIPasteboard 忽略我使用的图像方向?
我正在从相机中拍摄图像,并将其旋转到新的方向,然后将其粘贴到通用粘贴板上。但是,无论我向方向传递什么内容,稍后通过粘贴板粘贴命令粘贴的内容都会被定向,就好像它是 UIImageOrientationUp 一样。
CGImageRef croppedImageRef = CGImageCreateWithImageInRect([self CGImage], CGRectMake(rect.origin.y, [self size].width - rect.origin.x - rect.size.width, rect.size.height, rect.size.width));
UIImage *croppedImage = [UIImage imageWithCGImage:croppedImageRef scale:self.scale orientation:orientation];
CGImageRelease(croppedImageRef);
[[UIPasteboard generalPasteboard] setImage:croppedImage];
我使用类似的代码成功旋转相机中的图像并将其插入相册中:
CGImageRef croppedImageRef = CGImageCreateWithImageInRect([self CGImage], CGRectMake(rect.origin.y, [self size].width - rect.origin.x - rect.size.width, rect.size.height, rect.size.width));
UIImage *croppedImage = [UIImage imageWithCGImage:croppedImageRef scale:self.scale orientation:orientation];
CGImageRelease(croppedImageRef);
[self writeUIImageToCameraRoll:croppedImage withOrientation:orientation];
为什么我无法按照粘贴板的要求旋转图像?粘贴操作是否使用 EXIF 方向?如果是这样,imageWithCGImage是否将原始EXIF复制到新图像?
I am taking an image from the camera, and rotating it to a new orientation, and then pasting it onto the general pasteboard. However, no matter what I pass in to orientation, what ends up being pasted later by the pasteboard paste command is oriented as if it were UIImageOrientationUp.
CGImageRef croppedImageRef = CGImageCreateWithImageInRect([self CGImage], CGRectMake(rect.origin.y, [self size].width - rect.origin.x - rect.size.width, rect.size.height, rect.size.width));
UIImage *croppedImage = [UIImage imageWithCGImage:croppedImageRef scale:self.scale orientation:orientation];
CGImageRelease(croppedImageRef);
[[UIPasteboard generalPasteboard] setImage:croppedImage];
I use similar code to successfully rotate images from the camera and insert them into the photo album:
CGImageRef croppedImageRef = CGImageCreateWithImageInRect([self CGImage], CGRectMake(rect.origin.y, [self size].width - rect.origin.x - rect.size.width, rect.size.height, rect.size.width));
UIImage *croppedImage = [UIImage imageWithCGImage:croppedImageRef scale:self.scale orientation:orientation];
CGImageRelease(croppedImageRef);
[self writeUIImageToCameraRoll:croppedImage withOrientation:orientation];
How come I can't get the image rotated as I wish for the pasteboard? Is the paste action using an EXIF orientation? If so, is imageWithCGImage copying the original EXIF to the new image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信粘贴板更喜欢 PNG,它会去除附加到图像的任何 EXIF 数据。
NSLog( @"UIPasteboardTypeListImage: %@", UIPasteboardTypeListImage );
nets:解决方法是将 JPEG 数据保存到粘贴板:
或者从粘贴板获取图像后重置图像的方向:
I believe the pasteboard prefers PNG, which would strip any EXIF data attached to the image.
NSLog( @"UIPasteboardTypeListImage: %@", UIPasteboardTypeListImage );
nets:Options for work-arounds would be to save JPEG data to the pasteboard:
or reset the orientation of the image after fetching it from the pasteboard: