如何将旋转图像与背景图像合并?

时间:2012-09-11 11:45:09

标签: iphone

  

可能重复:
  How to merge two images after rotate the image?

我使用了前景图像旋转的两个图像,背景图像稳定。如何合并这两个图像?它不适合我。提前谢谢。

UIGraphicsBeginImageContext(itemSize);
CGRect backgroundImageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
CGRect foregroundImageRect = CGRectMake(rsImageView.frame.origin.x, rsImageView.frame.origin.y, rsImageView.frame.size.width, rsImageView.frame.size.height);
[backgroundImageView.image drawInRect:backgroundImageRect];
[rsImageView.image drawInRect:foregroundImageRect];
overlappedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

我正在使用此代码。但不合并旋转图像。它只合并最后一个图像帧。

1 个答案:

答案 0 :(得分:0)

这里imgDisplayImage是UIInageVew的实例,lastRotation是总旋转角度

    //...code...//
CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);

    CGContextTranslateCTM(context, [self.imgDisplayImage center].x, [self.imgDisplayImage center].y);
    CGContextRotateCTM(context, lastRotation);
    CGContextTranslateCTM(context,
                          -self.imgDisplayImage.frame.size.width * [[self.imgDisplayImage layer] anchorPoint].x,
                          -self.imgDisplayImage.frame.size.height * [[self.imgDisplayImage layer] anchorPoint].y);

        [self.imgDisplayImage.layer renderInContext:context];
    CGContextRestoreGState(context);
    // . . .