Andrei  Trotsko
Andrei Trotsko

Reputation: 347

Objective-C Save and load Image in app

What's the easiest way to save and load the image in the application. Clicking on the action shield option to download an image from the Gallery or from the camera, how to do that would be this picture load on another controller. And if a lot of pictures will then choose their desired URL. How best to implement such a feature? I had variant in coredate store string finding the index file. If anyone knows how to do this or know of a way of realisation of the half I would be very grateful.

Upvotes: 1

Views: 1214

Answers (2)

Ramani Hitesh
Ramani Hitesh

Reputation: 214

// Save Image ALAssetsLibrary & Save Gallery Folder: -(IBAction)save:(id)sender {

UIGraphicsBeginImageContextWithOptions(self.share_imageview.bounds.size, _share_imageview.opaque, 0.0);
[self.share_view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *visibleViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[self.library saveImage:visibleViewImage toAlbum:@"Photo Blender" withCompletionBlock:^(NSError *error) {
    if (error!=nil)
    {
        NSLog(@"Big error: %@", [error description]);
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Image saved to album." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];

    }
}];

}

Upvotes: 0

Nilesh Jha
Nilesh Jha

Reputation: 1636

You can use NSUserDefaults for storing image in the app and retrieving the same when You want to use them.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
////-------------------------------------------------------------------------------------------------------------------------------------------------

    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.imagePicked.image = chosenImage;
[[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(chosenImage) forKey:@"userImage"]
    [picker dismissViewControllerAnimated:YES completion:NULL];

}

//Retrieving the image

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
   NSData* imageData = [[NSUserDefaults standardUserDefaults] objectForKey:@"userImage"];
  UIImage* userImage = [UIImage imageWithData:imageData];
self.imagePicked.image = userImage;
}

For storing multiple images You can take a NSMutable arry.

Upvotes: 2

Related Questions