我有和 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();