【发布时间】:2013-05-07 07:46:09
【问题描述】:
我正在尝试在imagePickerController:didFinishPickingMediaWithInfo 中管理图像旋转,但经过多次尝试,我没有找到任何解决方案。我的最后一次尝试是:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// load the storyboard by name
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[ApplicationSupport getStoryBoardName] bundle:nil];
UploadViewController *uploadView = [storyboard instantiateViewControllerWithIdentifier:@"ViewUploadFile"];
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
NSDictionary *metadataImage = [info valueForKey:UIImagePickerControllerMediaMetadata];
uploadView.imageToUpload = image;
if([[metadataImage objectForKey:@"Orientation"] intValue] == 3) {
UIImage *imageRotated = [UIImage imageWithCGImage:[image CGImage] scale:[image scale] orientation:UIImageOrientationDown];
uploadView.dataToUpload = UIImagePNGRepresentation(imageRotated);
} else {
uploadView.dataToUpload = UIImagePNGRepresentation(image);
}
// ETC...
}
我不能也不想使用JPEGRepresentation。当 iPad 处于特定位置时,我需要将照片旋转 180°。
有什么想法吗?
【问题讨论】:
-
您是否尝试过使用 UIImageOrientationLeft 或 UIImageOrientationRight 而不是 Dowm。它会旋转吗?
-
经过几次尝试,我明白我不想改变方向“标志”。我需要“物理”旋转我的图像。所以我尝试了这个:
UIGraphicsBeginImageContext(image.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextRotateCTM(context, (90 * M_PI / 180)); [image drawAtPoint:CGPointMake(0, 0)]; UIImage *imageRotated = UIGraphicsGetImageFromCurrentImageContext(); uploadView.dataToUpload = UIImagePNGRepresentation(imageRotated);但它返回给我空白图像......
标签: ios objective-c xcode ipad uiimage