1

How can I make one image of several uiviews that have an imageview on it, with the scale and everything, I already found some code to put one image to another:

- (UIImage *)addImage:(UIImage *)imageView toImage:(UIImage *)Birdie {
    UIGraphicsBeginImageContext(imageView.size);

    // Draw image1
    [imageView drawInRect:CGRectMake(0, 0, imageView.size.width, imageView.size.height)];

    // Draw image2
    [Birdie drawInRect:CGRectMake(0, 0, Birdie.size.width, Birdie.size.height)];

    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return resultingImage;
}

This code make one image with two images at the point 0,0, I need to merge several images with the actual zoom to one image, I have one background image and several objects on it that I can zoom in and out and i want to make a final image with all the objects at their places and with their zoom, like photoshop, where you have several objects and you can merge them into one.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
edounl
  • 65
  • 1
  • 11
  • possible duplicate of [How to capture UIView to UIImage without loss of quality on retina display](http://stackoverflow.com/questions/4334233/how-to-capture-uiview-to-uiimage-without-loss-of-quality-on-retina-display) – Jasper Blues Nov 04 '13 at 12:41

1 Answers1

1

You can do it as follows:

Simply take the top-level view where all of the sub-views have been composited, and then:

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);

    if ([view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
    {
        //This only works on iOS7
        [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
    } 
    else 
    {
        //For iOS before version 7, use the following instead
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    }

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}
Jasper Blues
  • 28,258
  • 22
  • 102
  • 185
  • We should probably close this question as a duplicate of: http://stackoverflow.com/questions/4334233/how-to-capture-uiview-to-uiimage-without-loss-of-quality-on-retina-display . . unless you think there's something unique about your question vs that one? – Jasper Blues Nov 04 '13 at 12:41