Amink
Amink

Reputation: 35

iOS : How to save current image from my current UIView to photo album? I'm stuck with UIImageWriteToSavedPhotosAlbum

I have my current image that can swipe back and forward. All the image are inside a folder called pages. So when I am in the current view, I have an IBAction to save that current image to photo album. How to implement that task ? I have study this but I don't know how to start and i'm stuck.

M file :

I define UIImage.h

void UIImageWriteToSavedPhotosAlbum (
   UIImage  *image,
);

- (IBAction)saveMe{

   [UIImageWriteToSavedPhotosAlbum];

}

My Amendment code:

-(IBAction) saveToPhotoAlbum{




}

- (void) imageViewController:(UIImageView *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    UIImage *image = //i have 6 current UIImageview on my current main view. How do I get stated?



    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);






    [picker release];
}




- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;


    if (error)
        alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                           message:@"Unable to save image to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    else 
        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                           message:@"Image saved to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    [alert show];
    [alert release];
}

Upvotes: 0

Views: 2102

Answers (1)

Volodymyr B.
Volodymyr B.

Reputation: 3441

draw uiview to context

UIGraphicsBeginImageContext(size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

and use UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo); for save to album

Upvotes: 3

Related Questions