UIImagePickerController

- (void)getImageFromIpc
{
    // 1.判断相册是否可以打开
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) return;
    
    // 2. 创建图片选择控制器
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    
    // 3. 设置打开照片相册类型(显示所有相簿)
    ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    
    // 4.设置代理
    ipc.delegate = self;
    //设置图片编辑
    ipc.allowsEditing = YES;
    // 5.modal出这个控制器
    [self presentViewController:ipc animated:YES completion:nil];
}


- (void)getImageFromCamera
{
    // 1.判断相册是否可以打开
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) return;
    
    // 2. 创建图片选择控制器
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    
    // 照相机
    ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
    // 4.设置代理
    ipc.delegate = self;
    // 5.modal出这个控制器
    [self presentViewController:ipc animated:YES completion:nil];
}


#pragma mark -- --
// 获取图片后的操作
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // 销毁控制器
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    self.topImgView = self.headerview.IMGView;
    
    self.topImgView.image = info[UIImagePickerControllerOriginalImage] ;
}

-(NSString *)getIMGBsae64Str{
    if (!self.topImgView.image) {
        return nil;
    }
    NSData *imageData = [EditPic reSizeImageData:self.topImgView.image maxImageSize:800 maxSizeWithKB:300.0];
   return  [imageData base64Encoding];
}

你可能感兴趣的:(UIImagePickerController)