我正在制作一个iPhone应用程序,它从相机中加载图像,然后用户可以从库中选择第二个图像,移动/缩放/旋转第二个图像,然后保存结果。我使用ib中的两个uiImageView作为占位符,然后在触摸/捏取时应用转换。
当我必须同时保存两个图像时,问题就出现了。我使用第一个图像大小的矩形并将其传递给
UIGraphicsBeginImageContext
. 然后我试着用
CGContextConcatCTM
但我不明白它是如何工作的:
CGRect rect = CGRectMake(0, 0, img1.size.width, img1.size.height); // img1 from camera
UIGraphicsBeginImageContext(rect.size); // Start drawing
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect); // Clear whole thing
[img1 drawAtPoint:CGPointZero]; // Draw background image at 0,0
CGContextConcatCTM(ctx, img2.transform); // Apply the transformations of the 2nd image
但是我接下来需要做什么呢?img2.transform矩阵中包含哪些信息?文件
CGContextConcatchTM公司
不幸的是,对我没什么帮助。
现在我正试图用三角学(借助于
this answer
但是,既然有了转变,就必须有一种更简单、更优雅的方式来做到这一点,对吗?