0

When I chose a portrait photo from the library like that :
(source: hostingpics.net)

The UIImage returned by the library is rotated.

Here is my code :

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
    UIImage* originalImg = [editInfo objectForKey:UIImagePickerControllerOriginalImage];
    [self useImage:originalImg];
}

How can I avoid that ?

4

2 回答 2

1
self.imageData=[info objectForKey:@"UIImagePickerControllerOriginalImage"];    
CIImage *image = [[CIImage alloc] initWithImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
self.imageData=[UIImage imageWithCIImage:image scale:self.imageData.scale orientation:self.imageData.imageOrientation];

您可以使用以下方法来保留图像的方向:

 [UIImage imageWithCIImage:(CIImage *) scale:(CGFloat) orientation:(UIImageOrientation)];
 [UIImage imageWithCGImage:(CGImageRef) scale:(CGFloat) orientation:(UIImageOrientation)];
于 2013-04-12T04:22:52.547 回答
0

您之前是否使用应用程序中的图像选择器拍摄图像然后保存图像?如果是这样,您是否在保存图像时设置了方向?你需要。

考虑添加日志语句或调试以检查图像上设置的方向。

如果在图像上设置了方向,则 UIImageView 将自动正确渲染图像。

如果(将来)您要获取图像数据并将其上传到某个地方,那么您需要检查方向并重新绘制图像,同时对上下文应用适当的变换。

于 2013-04-11T22:29:27.983 回答