UIImagePNG代表...writeToFile始终是横向的



每次我使用相机拍照,然后保存时,图像总是横向的。这意味着我的Xib中的UIImageView是错误的。它的肖像——这正是我想要和期望的。我可以通过将图像旋转90度来纠正这一问题,但即使这样,我也不能禁用显示原始横向照片和动画旋转本身的动画。如何确保相机的UIImageView在保存时实际上处于纵向模式,而不是横向模式,以及如何在CGAffineTransformationMakeRotation期间禁用动画??

我发现这篇文章非常有用,它描述了在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];
}

相关内容

  • 没有找到相关文章

最新更新