Reputation: 253
I have and UIImageView with a smaller image than original image. and then i added many other UIImageView to the main imageview as the subviews. I also scale and rotate many subviews(imageview). Now i want to create the image from the original image with all sub view image attach on imageview, but keep position. my question is how can i draw many subview images into original image after scale and rotate them. i used CGContextRotateCTM but seem to be it rotate too much. Please help me my sample code is
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();
Upvotes: 2
Views: 1236
Reputation: 20541
just capture this whole view and after use with one image from your this whole image
- (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;
}
after capture this image , set it as a background and remove otherall images if its not required..
Upvotes: 2