What you are doing here is the transform
-property logoImageView
. This property indicates the transformation applied to the UIImageView
itself. Although this will cause the image to be rotated when the image is displayed, it will not change the base image.
Therefore, when you rotate the representation of the image and read the image
-property of your image, you still get the same image that you assigned to it, since the transformation applies to the representation, and not to the image itself.
What you want to do is draw an image on a CGContext
using a rotated transform. To establish this conversion, you must use the CGContextRotateCTM
function. This function sets the "Current Transformation Matrix", which defines the transformation that should be applied when drawing in context. I also use CGContextTranslateCTM
to move the image to the center of the context.
The final code might look like this:
CGSize newSize = [flowersImage size]; UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0); [flowersImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; CGContextTranslateCTM(UIGraphicsGetCurrentContext(), newSize.width / 2.f, newSize.height / 2.f); CGContextRotateCTM(UIGraphicsGetCurrentContext(), -M_PI/6.f); [appleImage drawAtPoint:CGPointMake(0.f - [appleImage size].width / 2.f, 0.f - [appleImage size].height / 2.f)]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
s1m0n source share