iOS调用相机/相册,并使用VPImageViewController(三方库)对图像处理(1)

来源:互联网 发布:性别刻板印象 知乎 编辑:程序博客网 时间:2024/06/09 14:05

VPImageViewController:三方库,实现对图片的剪切处理  http://code4app.com/ios/VPImageCropper/52d3796dcb7e84981b8b6d13(下载地址)


// buttonIndex表示当前的点击按钮的标号index索引(UIActionSheet的代理方法)

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // UIImagePickerController相册and相机对象
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.delegate = self;
    if (buttonIndex == 0) {
        // 从相册去头像
        ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    } else if (buttonIndex == 1) {
        // 去摄像头取相册
        ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    if (buttonIndex != 2) {
        // 启动相册 presentViewController
        [self presentViewController:ipc animated:YES completion:^{
            // 相册启动完成的回调函数 相册启动动画完成的callback回调函数
            NSLog(@"相册启动完毕 动画完毕");
        }];
    }
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet {
}

#pragma mark - Apple相册选择代理
// 选择了某个照片的回调函数/代理函数
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    // 取得我们选择的图片 info就包含了图片的所有信息(图片的UIImage *和图片的地址)
    // UIImagePickerControllerOriginalImage取得相册图片的原始图片的key
    // metadata元数据
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    
    // 苹果自带的相册消失
    [picker dismissViewControllerAnimated:NO completion:^{
        NSLog(@"相册关闭完毕 动画完毕");
    }];

//    headImageView.image = image;
//    // 剪切头像处理  VPImageCropperViewController图像剪切的Controller 设置了截图图片的大小
    VPImageCropperViewController *ihc = [[VPImageCropperViewController alloc] initWithImage:image cropFrame:CGRectMake(0, 100.0f, self.view.frame.size.width, self.view.frame.size.width) limitScaleRatio:3.0];

   ihc.delegate = self;

    // 启动一个图片选择器 框图选择
    [self presentViewController:ihc animated:YES completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

//点击图片的取消按钮 

  [picker dismissViewControllerAnimated:YES completion:nil];

}

#pragma mark - 图片切割的代理方法
// 选择了某个图片框图的完成函数
- (void)imageCropper:(VPImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage {
    // editedImage 就是最后的选择的图片
    [cropperViewController dismissViewControllerAnimated:NO completion:nil];
    ----》下面即可对取得的图片进行操作
    
    /* 进行滤镜处理 */
#if 0
    // FilterImageViewController图片滤镜的controller
    FilterImageViewController *fivc = [[FilterImageViewController alloc] init];
    // 把正方形图片editedImage传到图片滤镜上
    fivc.image = editedImage;
    NSLog(@"edit image is %@", editedImage);
   ----》滤镜处理之后可以对图片进行操作
#endif
}

0 0
原创粉丝点击