Reputation: 659
I have the following code
- (void)ComputeRotationWithRadians:(CGFloat)rad {
CGFloat width = exportImage.size.width;
CGFloat height = exportImage.size.height;
UIGraphicsBeginImageContext(CGSizeMake(width, height));
CGContextRef ctxt = UIGraphicsGetCurrentContext();
CGContextScaleCTM(ctxt, 1.0, -1.0);
CGContextTranslateCTM(ctxt, 0.0, -exportImage.size.height);
CGContextRotateCTM(ctxt, rad);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), exportImage.CGImage);
exportImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[imageView setImage:exportImage];
}
The issue is that the rotation happens around the bottom left corner, when it has been calculated around the center. Is there anyway to change this?
Upvotes: 0
Views: 771
Reputation: 35925
Your code is translating the matrix before rotating it. Try flipping the calls to CGContextConcatCTM
and CGContextTranslateCTM
so you rotate first. Or perhaps you are looking for something else?
Upvotes: 1