在IOS中怎么拿到自己相册中得图片
//说明:法1:获取本地相册图片 法2:摄像头拍照设为图片
成都网站建设、网站制作的开发,更需要了解用户,从用户角度来建设网站,获得较好的用户体验。创新互联多年互联网经验,见的多,沟通容易、能帮助客户提出的运营建议。作为成都一家网络公司,打造的就是网站建设产品直销的概念。选择创新互联,不只是建站,我们把建站作为产品,不断的更新、完善,让每位来访用户感受到浩方产品的价值服务。
//步骤:一、声明代理
//二、声明两个私有的button 和 一个 UIImageView 分别为:1、获取手机本地相册图片btnLocalLibrary 2、获取拍照图片btnCamera 3、 p_w_picpathHead
//三、对声明的控件初始化
//四、实现两个GetLocalPhoto.m里面的三个函数 1、-(void)btnSelect1 2、-(void)btnSelect2 3、-(void)p_w_picpathPickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
@property (nonatomic,strong)UIButton *btnLocalLibrary;
@property (nonatomic,strong)UIButton *btnCamera;
@property (nonatomic,strong)UIImageView *p_w_picpathHead;
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
//拿到手机相机,拍照
self.btnCamera = [UIButtonbuttonWithType:UIButtonTypeCustom];
[self.btnCamerasetImage:[UIImagep_w_picpathNamed:@"head.jpg"]forState:UIControlStateNormal];
self.btnCamera.center =CGPointMake(self.view.center.x*1.5,self.view.center.y*1.7);
self.btnCamera.bounds = CGRectMake(0, 0, 70, 70);
self.btnCamera.layer.cornerRadius =35;
self.btnCamera.layer.borderColor = [UIColorwhiteColor].CGColor;
self.btnCamera.layer.borderWidth =3.0;
self.btnCamera.clipsToBounds =YES;
[self.btnCameraaddTarget:selfaction:@selector(btnSelect1)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.btnCamera];
//从相册中获取头像
self.btnLocalLibrary = [UIButtonbuttonWithType:UIButtonTypeCustom];
[self.btnLocalLibrarysetImage:[UIImagep_w_picpathNamed:@"head.jpg"]forState:UIControlStateNormal];
self.btnLocalLibrary.center =CGPointMake(self.view.center.x*0.5,self.view.center.y*1.7);
self.btnLocalLibrary.bounds = CGRectMake(0, 0, 70, 70);
self.btnLocalLibrary.layer.cornerRadius =35;
self.btnLocalLibrary.layer.borderColor = [UIColorwhiteColor].CGColor;
self.btnLocalLibrary.layer.borderWidth =3.0;
self.btnLocalLibrary.clipsToBounds =YES;
[self.btnLocalLibraryaddTarget:selfaction:@selector(btnSelect2)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:self.btnLocalLibrary];
//头像
self.p_w_picpathHead = [[UIImageViewalloc]initWithFrame:CGRectMake(130,100,60,60)];
self.p_w_picpathHead.p_w_picpath = [UIImage p_w_picpathNamed:@"head.jpg"];
[self.view addSubview:self.p_w_picpathHead];
}
#pragma mark -摄像头拍照的图片
-(void)btnSelect1
{
//判断是否可以使用摄像头
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//打开摄像头
UIImagePickerController * picker = [[UIImagePickerControlleralloc]init];
picker.delegate = self;
picker.sourceType =UIImagePickerControllerSourceTypeCamera;
[selfpresentViewController:pickeranimated:YEScompletion:nil];
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"不能使用照相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
}
}
#pragma mark -拿已经存在手机相册里的图片
-(void)btnSelect2
{
// UIImagePickerController
//判断是否可以使用相册
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController * picker = [[UIImagePickerControlleralloc]init];
picker.delegate = self;
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
[selfpresentViewController:picker animated:YEScompletion:nil];
}else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"不能使用相册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
}
}
-(void)p_w_picpathPickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//将照片显示在屏幕上
//获取当前拍摄的照片
UIImage * p_w_picpath = [infovalueForKey:UIImagePickerControllerOriginalImage];
self.p_w_picpathHead.p_w_picpath = p_w_picpath;
UIImage * p_w_picpath2 = [infovalueForKey:UIImagePickerControllerOriginalImage];
self.p_w_picpathHead.p_w_picpath = p_w_picpath2;
//将照片存放到相册当中
if (picker.sourceType ==UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(p_w_picpath, p_w_picpath2,nil,nil);
}
[selfdismissViewControllerAnimated:YEScompletion:nil];
}
本文名称:在IOS中怎么拿到自己相册中得图片
分享地址:http://myzitong.com/article/gchpgi.html