在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://bzwzjz.com/article/gchpgi.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站建设公司 高端网站设计 成都网站建设 成都网站制作公司 达州网站设计 营销网站建设 温江网站设计 成都网站设计公司 高端网站建设 成都定制网站建设 重庆企业网站建设 成都网站设计 网站设计 教育网站设计方案 网站建设 成都网站建设流程 网站设计公司 网站设计 成都商城网站建设 H5网站制作 响应式网站设计 四川成都网站制作