0

可能重复:
旋转图像后如何合并两个图像?

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

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();

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

4

1 回答 1

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);
    // . . . 
于 2012-09-11T11:51:23.623 回答