【发布时间】:2012-11-13 19:23:47
【问题描述】:
我有一个比原始图像更小的图像的 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();
【问题讨论】:
-
我不确定我是否正确理解了您的问题。您的主视图是否包含所有旋转的子视图?还是您只是想在另一个视图之上绘制一些视图?
-
你想要什么??要将当前视图保存为目录中的图像??
-
不,例如我有大小为 (1000, 1000) 的原始图像,但在 UIImageView 中我将原始图像调整为新大小 100 x 100,然后我将许多小图像添加到 UIImageView(大小 100x100) .现在我想将所有小图像(子视图)绘制到大小为 1000x1000 且位置相同的原始图像
标签: iphone objective-c ios image uiimage