我想将2个UIImageView中的2个图像合并为1个图像,并在屏幕上显示“正确”位置,角度,比例比例。如何将2个UIImageView中的2个图像合并为1个图像
在我的项目中,有2的UIImageView - ImageView的是主要的UIImageView - topImageView是覆盖的UIImageView是可以拖动,旋转,缩放
我可以保存图像合并以得出2幅图像,但错了位置,角度,比例尺度。
这是我的代码:
UIImage *img = topImageView.image;
UIImage *bottomImg = self.imageView.image;
CGSize bounds = self.imageView.image.size;
UIGraphicsBeginImageContext(bounds);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, topImageView.image.size.width * 0.5, topImageView.image.size.height * 0.5);
CGFloat angle = atan2(topImageView.transform.b, topImageView.transform.a);
CGContextRotateCTM(ctx, angle);
[topImageView.image drawInRect:CGRectMake(-topImageView.image.size.width * 0.5,
-topImageView.image.size.height * 0.5,
topImageView.image.size.width,
topImageView.image.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsBeginImageContext(bounds);
[bottomImg drawInRect:CGRectMake(0, 0, bounds.width, bounds.height)];
[newImage drawInRect:CGRectMake(topImageView.frame.origin.x,
topImageView.frame.origin.y,
newImage.size.width,
newImage.size.height)];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
任何想法帮助我吗?非常感谢!
复制http://stackoverflow.com/questions/9208951/ios-merging-两图像 - 的-不同尺寸 –