You need to make your graphics context large enough for the rotated image. You use image.size, but you must use the rotated size as an argument for the UIGraphicsBeginImageContext. Also, your drawInRect argument is incorrect. You need to compensate for the (rotated) beginning of x, which defines the y source image of the final image as follows: βUpβ to half the original height (which completely excludes the final image from the top of the drawing context), then βdownβ to the full original width, which is final image height.
const CGSize imageSize = image.size; UIGraphicsBeginImageContext(CGSizeMake(imageSize.height, imageSize.width)); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(context, 0.5f * imageSize.width, 0.5f * imageSize.height ) ; CGContextRotateCTM(context, -1.5707963267949) ; [image drawInRect:(CGRect){ { imageSize.height * 0.5 - imageSize.width, -imageSize.width * 0.5f }, imageSize }]; UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
source share