title: Creating an app's own Photo Gallery (iOS)
body: <p>Hello I have an application that takes pictures and displays the newly taken pictures to the image view. I can save the image and load it again. It is saved in the app's directory. Is it possible to create a album just for the use of that app? The pictures shouldn't be seen in the iPhone's photo gallery for security purposes. If it is possible, can anyone explain to me how to do it? Here are my current codes.</p>
  
  <p><strong>ViewController.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface ViewController : UIViewController &lt;UIImagePickerControllerDelegate, UINavigationControllerDelegate&gt; {
      UIImagePickerController *picker;
      UIImagePickerController *picker2;
      UIImage *image;
      IBOutlet UIImageView *imageView;
  }
  
  -(IBAction)TakePhoto;
  -(IBAction)ChooseExisting;
  - (IBAction)btnSave:(id)sender;
  - (IBAction)btnLoad:(id)sender;
  
  @end
  </code></pre>
  
  <p><strong>ViewController.m</strong></p>
  
  <pre><code>#import "ViewController.h"
  
  @interface ViewController ()
  
  @end
  
  @implementation ViewController
  
  -(IBAction)TakePhoto{
      picker = [[UIImagePickerController alloc]init];
      picker.delegate=self;
      [picker setSourceType:UIImagePickerControllerSourceTypeCamera];
      [self presentViewController:picker animated:YES completion:NULL];
     // [picker release];
  
  
  }
  
  - (void)loadImage
  {
  
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
      NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; //Add the file name
      NSData *pngData = [NSData dataWithContentsOfFile:filePath];
      image = [UIImage imageWithData:pngData];
  }
  -(IBAction)ChooseExisting{
      picker2 = [[UIImagePickerController alloc]init];
      picker2.delegate=self;
      [picker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
      [self presentViewController:picker2 animated:YES completion:NULL];
      // [picker release];
  
  }
  
  - (NSString *)documentsPathForFileName:(NSString *)name
  {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
      NSString *documentsPath = [paths objectAtIndex:0];
  
      return [documentsPath stringByAppendingPathComponent:name];
  }
  - (IBAction)btnSave:(id)sender {
  
      NSData *pngData = UIImagePNGRepresentation(image);
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
      NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; //Add the file name
      [pngData writeToFile:filePath atomically:YES]; //Write the file
  }
  - (IBAction)btnLoad:(id)sender {
      [self loadImage];
      [imageView setImage:image];
  }
  
  
  
  -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
      image = [info objectForKey:UIImagePickerControllerOriginalImage];
      [imageView setImage:image];
      [self dismissViewControllerAnimated:YES completion:NULL];
  }
  
  - (void)viewDidLoad
  {
      [self loadImage];
      [imageView setImage:image];
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  @end
  </code></pre>