0

as per my title, i have a 2 picture which i will like to save it as one photo.

one of the photo allow user to gesture such as rotate, zoom and move around.

how do i save user moved and rotated picture ?


screen shot of the phone                                    saved image

iphone screen Saved image

the code below are referred from How to combine/ merge 2 images into 1

UIImage *image = nil;

        CGSize newImageSize = CGSizeMake(cropImage.frame.size.width, cropImage.frame.size.height);
        if (UIGraphicsBeginImageContextWithOptions != NULL) {
            UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
        } else {
            UIGraphicsBeginImageContext(newImageSize); 
        }

    // Draw image1
    [maskImage.image drawInRect:CGRectMake(0,0, maskImage.frame.size.width,maskImage.frame.size.height)];
    // Draw image2
    [cropImage.image drawInRect:CGRectMake(cropImage.frame.origin.x, cropImage.frame.origin.y, cropImage.frame.size.width, cropImage.frame.size.height)];

    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
Community
  • 1
  • 1
Desmond
  • 5,001
  • 14
  • 56
  • 115

1 Answers1

2

Try this piece of code

//Hide your views here like save button
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContext(screenRect.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil);  
 //Show again your hidden views here like save button
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184