RSS

Tag Archives: uiimagepicker

ios UIImagePicker tutorial


MyImagePickerViewController.h

#import <UIKit/UIKit.h>

@interface MyImagePickerViewController : UIViewController
<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    UIImagePickerController *ipc;
    IBOutlet UIImageView *bgImage;

}
@property (nonatomic,retain) UIImageView *bgImage;

-(IBAction) buttonClicked;

@end

MyImagePickerViewController.m

#import "MyImagePickerViewController.h"

@implementation MyImagePickerViewController


@synthesize bgImage;

-(IBAction) buttonClicked{

ipc=[[UIImagePickerController alloc]init];
ipc.delegate = self;

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
}else
{
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

[self presentModalViewController:ipc animated:YES];

}


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

//release picker

[[picker parentViewController]dismissModalViewControllerAnimated:YES];

[picker release];
}


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

//set image

bgImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
//release picker

[[picker parentViewController]dismissModalViewControllerAnimated:YES];

[picker release];

}







- (void)dealloc
{
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

 

Advertisements
 
1 Comment

Posted by on May 14, 2012 in iphone

 

Tags: ,