drawAtPoint with rotation
-
15-11-2019 - |
Question
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.
Solution
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];
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow