I've been struggling with this for hours. Affine transforms never seem to do what I expect them to.
CGContextSaveGState (ctx);
float w = self.frame.size.width;
float h = self.frame.size.height;
CGContextRotateCTM (ctx, angle);
CGContextTranslateCTM (ctx, w/2, -h/2);
CGRect r = CGRectMake (0,0, w, h);
CGContextDrawImage (ctx, r, image.CGImage);
CGContextRestoreGState (ctx);
I have a UIImage called image, I have a CGImage that is accessible through ctx. I want to rotate UIImage from its center by an angle, and draw it on top of the CGImage.
If I rotate and then translate, the UIImage gets streteched in a bad way. If I translate and then rotate, same result.
Any clues on how to do this? Thank you.