每次我用相机拍照,然后保存,图像总是横向的。这意味着我的 Xib 中的 UIImageView 是错误的。它的肖像——这是我想要和期待的。我可以通过将图像旋转 90 度来纠正此问题,但即便如此,我也无法禁用显示原始风景照片的动画,然后是动画旋转本身。如何确保来自相机的 UIImageView 在保存时实际上处于纵向模式而不是横向模式,以及如何在 CGAffineTranformationMakeRotation 期间禁用动画?
问问题
4294 次
1 回答
2
我发现这篇文章很有帮助,它描述了在保存之前向 UIImage 添加一个类别来旋转图像:
http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/
然后,一旦实现了类别,您将执行以下操作:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *originalImage, *editedImage, *rotatedImage;
editedImage = (UIImage *)[info objectForKey:UIImagePickerControllerEditedImage];
originalImage = (UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage];
if (editedImage)
{
rotatedImage = [editedImage rotate:UIImageOrientationRight];
}
else
{
rotatedImage = [originalImage rotate:UIImageOrientationRight];
}
NSString *f = @"/set/this/to/your/file/name";
[UIImagePNGRepresentation(rotatedImage) writeToFile:f atomically:YES];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
于 2011-06-15T13:57:40.507 回答