4

I am new in iPhone and in learning phase now a days. Actually i want to implement that i read images stored in my iPhone PHOTO Gallery and then display it onto my application.

I have searched in many Search Engines but could not find any thing. You all are professionals over here. Please guide me thrrough some code or some tutorial.

Thanks alot

Shah
  • 4,990
  • 10
  • 48
  • 70
  • 1
    Read the documentation and search for tutorial about UIImagePickerController. You will get what you want – stack2012 Jul 13 '11 at 05:48

3 Answers3

11

Edit

Also check out this question/answer and the method that is used to get the image from uiimagepickercontroller as the method that i have mentioned earlier is deprecated.

didFinishPickingMediaWithInfo return nil photo


check out the documentation http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html and check out this link

http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/

It has sample examples about the same.

You can use these methods to get the image in you UIImageView object

- (void)selectPhotos
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:nil];
    //Deprecated In IOS6[self presentModalViewController:picker animated:YES]; 
    [picker release];
}

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{
    imageView.image = image;
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
Community
  • 1
  • 1
Robin
  • 10,011
  • 5
  • 49
  • 75
  • Thanks Robin Nice and Simple. But isn't is possible that i read all the images stored in my library and display them onto my application without opening up the Built in Library.?? – Shah Jul 13 '11 at 06:08
  • ook .. Is it possible that i can select multiple images form the library at once and get all those onto my application.? – Shah Jul 13 '11 at 06:23
  • No you cant as you can see there is only one uiimage that can be fetched at a time so you dont have any other choice but to use it multiple no. of times. – Robin Jul 13 '11 at 06:31
  • use [self dismissViewControllerAnimated:YES completion:NULL]; instead of [[picker parentViewController] dismissModalViewControllerAnimated:YES]; – Ramdhas Apr 05 '14 at 13:13
5

You can access the iPhone image library like this and select the image from there

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
        {
            if (picker == nil) {
                picker = [[UIImagePickerController alloc] init];
                picker.allowsEditing = NO;

            }
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.delegate = self;
            // Make camera view full screen:
            picker.wantsFullScreenLayout = YES;
            [self.navigationController presentModalViewController:picker animated:YES];
        }

And then implement the delegate method to get the image...

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

    cameraClickedImage=[info valueForKey:UIImagePickerControllerOriginalImage];
     UIImage *thumbImage = [cameraClickedImage imageByScalingAndCroppingForSize:CGSizeMake(320, 480)];
    clickedImageView.image =thumbImage;
    [picker1 dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker1 {
    NSLog(@"Cap1");
    [picker1 dismissModalViewControllerAnimated:YES];
    [self.navigationController popViewControllerAnimated:NO];
}

Hope this will help you.......... Cheers......

Sabby
  • 2,586
  • 2
  • 27
  • 41
0

It works for me in the following way using iOS SDK 6.1 with Xcode 4.6.

First, make an UIImagePickerControllerDelegate protocol like that in your viewcontroller.h file:

@interface MyViewController : UIViewController<UIImagePickerControllerDelegate>

Then implement the following methods. I have a button named Choose:

- (IBAction)btnPicChooseTouched:(id)sender {
   UIImagePickerController *picker = [[UIImagePickerController alloc]init];
   picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
   picker.delegate = self;
   [self presentModalViewController:picker animated:YES];
}

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    imgProfilePic.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [picker dismissModalViewControllerAnimated:YES];
}

-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissModalViewControllerAnimated:YES];
}
honk
  • 9,137
  • 11
  • 75
  • 83
OSXMonk
  • 581
  • 6
  • 6