How to Rotate a UIImage 90 degrees?

前端 未结 19 857
天涯浪人
天涯浪人 2020-11-22 08:45

I have a UIImage that is UIImageOrientationUp (portrait) that I would like to rotate counter-clockwise by 90 degrees (to landscape). I don\'t want

19条回答
  •  感情败类
    2020-11-22 09:01

    As strange as this seems, the following code solved the problem for me:

    + (UIImage*)unrotateImage:(UIImage*)image {
        CGSize size = image.size;
        UIGraphicsBeginImageContext(size);
        [image drawInRect:CGRectMake(0,0,size.width ,size.height)];
        UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return newImage;
    }
    

提交回复
热议问题