UIImagePNGRepresentation … writeToFile is always landscape

不打扰是莪最后的温柔 提交于 2019-12-01 07:38:27

I found this post to be very helpful, it describes adding a category to UIImage to do the rotation of the image before you save it:

http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/

And then once the category is implemented, you would do something like this:

- (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];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!