大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

在IOS中怎么拿到自己相册中得图片-创新互联

//说明:法1:获取本地相册图片 法2:摄像头拍照设为图片

丹凤ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

//步骤:一、声明代理

//二、声明两个私有的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

{

  [super viewDidLoad];

  // Do any additional setup after loading the view.

  //拿到手机相机,拍照

  self.btnCamera = [UIButton buttonWithType:UIButtonTypeCustom];

  [self.btnCamera setImage:[UIImage p_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 = [UIColor whiteColor].CGColor;

  self.btnCamera.layer.borderWidth = 3.0;

  self.btnCamera.clipsToBounds = YES;

  [self.btnCamera addTarget:self action:@selector(btnSelect1) forControlEvents:UIControlEventTouchUpInside];

  [self.view addSubview:self.btnCamera];

  //从相册中获取头像

  self.btnLocalLibrary = [UIButton buttonWithType:UIButtonTypeCustom];

  [self.btnLocalLibrary setImage:[UIImage p_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 = [UIColor whiteColor].CGColor;

  self.btnLocalLibrary.layer.borderWidth = 3.0;

  self.btnLocalLibrary.clipsToBounds = YES;

  [self.btnLocalLibrary addTarget:self action:@selector(btnSelect2) forControlEvents:UIControlEventTouchUpInside];

  [self.view addSubview:self.btnLocalLibrary];

  //头像

  self.p_w_picpathHead = [[UIImageView alloc]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 ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

  {

    //打开摄像头

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

    picker.delegate = self;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:nil];

  }

  else

  {

    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"不能使用照相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

    [alert show];

  }

}

#pragma mark -拿已经存在手机相册里的图片

-(void)btnSelect2

{

//  UIImagePickerController

  //判断是否可以使用相册

  if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

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

    picker.delegate = self;

    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:picker animated:YES completion: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 = [info valueForKey:UIImagePickerControllerOriginalImage];

  self.p_w_picpathHead.p_w_picpath = p_w_picpath;

  UIImage * p_w_picpath2 = [info valueForKey:UIImagePickerControllerOriginalImage];

  self.p_w_picpathHead.p_w_picpath = p_w_picpath2;

  //将照片存放到相册当中

  if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {

    UIImageWriteToSavedPhotosAlbum(p_w_picpath, p_w_picpath2,nil, nil);

  }

  [self dismissViewControllerAnimated:YES completion:nil];

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享名称:在IOS中怎么拿到自己相册中得图片-创新互联
本文路径:http://dzwzjz.com/article/dojjog.html
在线咨询
服务热线
服务热线:028-86922220
TOP