我和UIImageView的图像比原始图像小。然后我将许多其他UIImageView作为子视图添加到主imageview。我还缩放和旋转许多子视图(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();
答案 0 :(得分: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;
}
捕获此图像后,将其设置为背景,如果不需要,则删除其他图像。