views:

193

answers:

1

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?

+1  A: 

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?

fbrereto
I have changed the code, see above, still does not work
woody993
You are still translating before rotating. You need to call CGContextRotateCTM, then CGContextTranslateCTM.
fbrereto
Now it just does it with the top left corner
woody993