1

I am having trouble drawing my imageView.image in the correct position using drawAtPoint. In the app I have used CGAffineTransformMakeRotation to rotate the image view, but when I want to save the imageView as part of a merge with others using UIGraphicsGetImageFromCurrentImageContext I don't know how to tell it to rotate.. all I am doing is rotating 180 degrees. here is the code I am using to merge it with another image.

UIGraphicsBeginImageContext(imageView.bounds.size); 

[imageView.image drawAtPoint:CGPointMake(-40,0)];
[topView.image drawAtPoint:CGPointMake(0,160)];

UIImage *mergedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

So my question is: How do I drawAtPoint with rotation of 180 degrees or 3.14159265 radians?

Thanks in advance.

Wez
  • 10,555
  • 5
  • 49
  • 63

1 Answers1

4

You can apply a transform to the image content, so all subsequent painting operation will be drawn with that transform, e.g. (untested)

UIGraphicsBeginImageContext(size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextRotateCTM(c, M_PI/6);
[image drawAtPoint:CGPointZero];
...
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • Awesome thanks! I used this to rotate the background image in a separate image context and then merge it with the others in a new one. – Wez May 18 '11 at 22:44