2

我有和 UIImageView 的图像比原始图像更小。然后我在主图像视图中添加了许多其他 UIImageView 作为子视图。我还缩放和旋转许多子视图(imageview)。现在我想从原始图像创建图像,所有子视图图像都附加在 imageview 上,但保持位置。我的问题是如何在缩放后将许多子视图图像绘制成原始图像并旋转它们。我使用了 CGContextRotateCTM 但似乎旋转太多了。请帮助我我的示例代码是

CGContextRef context = UIGraphicsGetCurrentContext();
[originalImage drawAtPoint:CGPointZero];
for(UIView *aView in [self.mainImageView subviews]){
    float rate = 1000/self.mainImageView.frame.size.width;
    if(aView.tag != DELETE_ATTACH_IMAGEVIEW_TAG && aView.tag != ROTATE_ZOOM_IMAGEVIEW_TAG){
        CGRect rect = CGRectMake(aView.frame.origin.x*rate, aView.frame.origin.y*rate, aView.frame.size.width *rate, aView.frame.size.height*rate);
        if([aView isKindOfClass:[CustomImageView class]]){
            CustomImageView *temp = (CustomImageView *)aView;
            float rotation = [temp rotation];
            UIImage *tempImage= temp.image;
            CGContextRotateCTM(context, rotation);
            [tempImage drawInRect:rect];
        }

    }

}
originalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
4

1 回答 1

2

只需捕获整个视图,然后使用整个图像中的一个图像

- (UIImage *)captureView {

   //hide controls if needed
    CGRect rect = [self.view bounds];

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];   
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;

}

捕获此图像后,将其设置为背景并删除其他所有图像(如果不需要)..

于 2012-11-26T10:38:57.797 回答