Iphone Developer
Iphone Developer

Reputation: 163

Saving the edited image in camera roll

I'm working on an Acne app in which I have to choose image from UIImagePicker and after adding subViews to it I want to save it in camera roll.

Problem: If I add UIImageView as a subView to the superView, the pickerImage does not save with subView.

And if I add that UIImage as subView to the Picker Image, I am unable to move the added UIImage Views.

I am using the following code for saving images:

-(IBAction)savePhoto
{


NSParameterAssert(imgToDisplayFromPicker.image);
UIImageWriteToSavedPhotosAlbum(imgToDisplayFromPicker.image, nil, nil, nil);


}

Upvotes: 0

Views: 311

Answers (1)

Iphone Developer
Iphone Developer

Reputation: 163

Finally Found the Solution :

CGRect contextRect = CGRectMake(6, 6, 302, 230);

UIGraphicsBeginImageContext(contextRect.size);

[self.view.layer renderInContext : UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], contextRect);

UIImage * newImage = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:viewImage.imageOrientation];

UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);

Upvotes: 2

Related Questions