I am making an iPhone application that downloads an image from a camera, and then the user can select the second image from the library, move / scale / rotate this second image, and then save the result. I use two UIImageViews in IB as placeholders, and then apply touch / pinch transforms.
The problem arises when I need to save both images together. I use the size rectangle of the first image and pass it to UIGraphicsBeginImageContext. Then I tried to use CGContextConcatCTM, but I can’t figure out how this works:
CGRect rect = CGRectMake(0, 0, img1.size.width, img1.size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
[img1 drawAtPoint:CGPointZero];
CGContextConcatCTM(ctx, img2.transform);
But what do I need to do next? What information is stored in the img2.transform matrix? The documentation for CGContextConcatCTMnot really helps me. Now I'm trying to solve this by calculating the points and angle using trigonometry (using this answer ), but since there is a transformation there, to be a simpler and more elgetic way to do this, right?
source
share