码迷,mamicode.com
首页 > 移动开发 > 详细

获取手机本地的图片或者照相机照像的图片 为头像

时间:2015-12-19 12:27:51      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

第一步点击获取头像按钮 下面为按钮执行方法

判断设备是否具有照像机功能有的话执行前者方法没有执行后者方法

UIActionSheet *actionSheet;

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){

actionSheet = [[UIActionSheet alloc]initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相册选

择", nil,nil];

}else{

actionSheet = [[UIActionSheet alloc] initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消"destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];

}

actionSheet.tag = 1000;

[actionSheet showInView:self.view];

第二步 执行调用相机或者相册方法 当然了还要引用代理UINavigationControllerDelegate, UIImagePickerControllerDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

if (actionSheet.tag == 1000) {

NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

// 判断是否支持相机

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

switch (buttonIndex) {

case 0:

sourceType = UIImagePickerControllerSourceTypeCamera;

break;

case 1:

//来源:相册

break;

case 2:

return;

}

}

else {

if (buttonIndex == 2) {

return;

} else {

sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

}

}

// 跳转到相机或相册页面

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

imagePickerController.delegate = self;

imagePickerController.allowsEditing = YES;

imagePickerController.sourceType = sourceType;

[self presentViewController:imagePickerController animated:YES completion:^{

}];

}

}

第三步就是确定头头像了

#pragma mark - 头像

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

{

[picker dismissViewControllerAnimated:YES completion:nil];

UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

NSLog(@"%@",image);

_faceImage = image;

[_tableView reloadData];

}

第四步就是你要把选中的图片显示在上面地方就显示在上面地方 这图片就是 _faceImage直接调用就好

获取手机本地的图片或者照相机照像的图片 为头像

标签:

原文地址:http://www.cnblogs.com/daijiahong/p/5058781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!