Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save UIImage to Photo Album with writeImageToSavedPhotosAlbum

I'm trying to save a UIImage to Photo Album. I've tried severl methods the last one is:

-(IBAction)captureLocalImage:(id)sender{

[photoCaptureButton setEnabled:NO];

// Save to assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library writeImageToSavedPhotosAlbum: imageView.image.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *error2)
 {
     //             report_memory(@"After writing to library");
     if (error2) {
         NSLog(@"ERROR: the image failed to be written");
     }
     else {
         NSLog(@"PHOTO SAVED - assetURL: %@", assetURL);
     }

     runOnMainQueueWithoutDeadlocking(^{
         //                 report_memory(@"Operation completed");
         [photoCaptureButton setEnabled:YES];
     });
 }];  

}

imageView is a UIImageView which contain the image I want to save. On log I got "PHOTO SAVED - assetURL: (null)" and the photo doesn't save to library.

What am I doing wrong?

like image 246
Idan Avatar asked Oct 02 '12 10:10

Idan


1 Answers

just use this bellow line for save the image in your photo library

UIImageWriteToSavedPhotosAlbum(imageView.image,nil,nil,nil);

:)

like image 118
Paras Joshi Avatar answered Oct 19 '22 23:10

Paras Joshi