In __.h file

At first you have to add two delegates

<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

In __.m file

For loading Photo Library

-(void)loadImageLibrary
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
return;
}
UIImagePickerController *photoPicker = nil;
if(photoPicker == NULL)
{
photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.allowsImageEditing = NO;
}
photoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentModalViewController:photoPicker animated:YES];
[pool release];
}

For picing picture through Camera use this:

-(void)captureImageByCamera
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
return;
}
UIImagePickerController *photoPicker = nil;
if(photoPicker == NULL)
{
photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.allowsImageEditing = NO;
}
photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera;

[self presentModalViewController:photoPicker animated:YES];
[pool release];
}

For loading Photo Gallery

-(void)loadImageGallery
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
return;
}
UIImagePickerController *photoPicker = nil;
if(photoPicker == NULL)
{
photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.allowsImageEditing = NO;
}
photoPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

[self presentModalViewController:photoPicker animated:YES];
[pool release];
}

#pragma mark photoPicker delegate
– (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *selectedImage = [info objectForKey:@”UIImagePickerControllerOriginalImage”];
//NSData* imageData = UIImagePNGRepresentation(selectedImage);
delegate.Image = selectedImage;
[self.addMealTable reloadData];
NSLog(@”sdklfh”);
[picker dismissModalViewControllerAnimated:YES];
}

– (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{

[picker dismissModalViewControllerAnimated:YES];

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s