2

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();
Omarj
  • 1,151
  • 2
  • 16
  • 43
  • I am not sure I understand correctly your question. Does your main view contains all the rotated subviews? Or are you trying to just draw some views on top of another? – sergio Nov 26 '12 at 10:25
  • http://stackoverflow.com/q/2214957/1030951 , read it – HarshIT Nov 26 '12 at 10:32
  • what you want exact?? you want to save current view as an image in directory?? – Paras Joshi Nov 26 '12 at 10:35
  • No,for example i have original image with size (1000, 1000) but in UIImageView i resize original image to new size 100 x 100, and then i add many small image to UIImageView(size 100x100). Now i want to draw all small image (sub views) to original image with size 1000x1000 with same position – Quang Phạm Công Nov 26 '12 at 10:51

1 Answers1

2

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..

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • thanks for your help, but i want full size of original image, i ever tried your code and i get small image in large image if i change size of context – Quang Phạm Công Nov 26 '12 at 10:52
  • @QuangPhạmCông hey mate i not understand what you want but if you want to just capture backimage or full image of background then use bounds of background image and also hide some images or controls if you not want to captured with original image.. i hope you understand it mate.. :)] – Paras Joshi Nov 26 '12 at 10:55
  • I just want to save uiimage view and all sub views on it into 1 image but with high resolution, larger size than uiimageview frame – Quang Phạm Công Nov 26 '12 at 14:59
  • oh ok mate if i got solution about your this requirement then i'll post code ok mate.. :) – Paras Joshi Nov 27 '12 at 05:59