I'm just trying to rotate a UIImage around its center using the following piece of code:
- (UIImage *) rotateImage: (UIImage *)image angle:(CGFloat)angleInRadian
{
float newSide = MAX([image size].width, [image size].height);
CGSize size = CGSizeMake(newSide, newSide);
UIGraphicsBeginImageContext(size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, newSide/2, newSide/2);
CGContextRotateCTM(ctx, angleInRadian);
CGContextDrawImage(UIGraphicsGetCurrentContext(),CGRectMake(-[image size].width/2,-[image size].height/2,size.width, size.height),image.CGImage);
//CGContextTranslateCTM(ctx, [image size].width/2, [image size].height/2);
UIImage *i = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return i;
}
Here is a sample of the results I got:
Input image:
Result Image for angle = 0 radians :
The result image is flipped but I'm not sure why? Any idea about what I'm doing wrong?
Thanks in advance.