IOS7-UIImagePickerController使用

@interface CapturePicViewController ()
@property(nonatomic,retain) UIImagePickerController *imgPickerCtl;
@end

@implementation CapturePicViewController
@synthesize imgPickerCtl;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self loadImgPicker];
    
}
- (void)loadImgPicker
{
    imgPickerCtl = [[UIImagePickerController alloc]init];
    //调用摄像头捕捉图片显示出来
    //Camera
    imgPickerCtl.sourceType = UIImagePickerControllerSourceTypeCamera;
    //读取相册的图片显示出来
    //photo library
    //imgPickerCtl.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imgPickerCtl.delegate = self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self presentViewController:imgPickerCtl animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [imgPickerCtl dismissViewControllerAnimated:YES completion:^{
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        [self.view addSubview:imageView];
    }];
}

你可能感兴趣的:(IOS,IOS,图片)