我想將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-兩圖像 - 的-不同尺寸 –