iOS调用相机/相册,并使用VPImageViewController(三方库)对图像处理(1)
2015-03-06 16:11
281 查看
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
}
// 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
}
相关文章推荐
- [IOS 图像处理]--相机的各种处理效果DLCImagePickerController
- iOS使用UIImagePickerController调用系统相机、相册与图库
- ios开发学习笔记--调用相册或相机(UIImagePickerController)
- Xamarin.iOS-UIImagePickerController调用相机和获取相册列表【控件篇】
- ios 调用系统相机,图库,相册。将照片保存在相册,保存图片在本地,UIImagePickerController
- iOS开发中使用相机或系统相册的一些问题总结(UIImagePickerController)
- iOS图片处理(一)————调用系统相机和相册获取图片,给相机添加自定义覆盖物
- iOS相机相册调用 — UIImagePickerController
- iOS图片处理(一)调用系统相机和相册获取图片,给相机添加自定义覆盖物
- [iOS 相机相册调用] UIImagePickerController 简单实用 [转]
- IOS - 使用 QBImagePickerController 从系统相册选取多张照片
- android使用WebView加载html input标签调用手机相机相册 后添加扫码功能
- Android调用系统相册和相机选择图片并显示在imageview中
- iOS相机相册调用 — UIImagePickerController
- android 使用本机相机照相或用本地相册更新imageview里面的图片
- iOS UICollectionViewController基本使用方法和简单的相册实现
- 关于IOS开发中addSubView上去的viewController的viewWillAppear 和viewDidAppear 等调用的总结
- IOS: 正确使用PresentModalViewController
- iOS 6新特性UIActivityViewController使用教程(一)
- 从 相机 或者相册 获取图片显示在ImageView 上