自定义照相机界面之cameraOverlayView和UIImagePickerControllerEditedImage
来源:互联网 发布:淘宝自助服务在哪 编辑:程序博客网 时间:2024/05/22 13:10
默认情况下 ,调用照相机的话,照相机下方有个白色的圆形按钮,这个按钮是可以自定义的,也可以隐藏,
<pre name="code" class="objc"> imagePicker.showsCameraControls=NO;//禁用摄像头控件如果想自定义界面的话,可以调用摄像头控件的隐藏,并覆盖图层,或者说叠加层
<pre name="code" class="objc"><span style="color: rgb(51, 51, 51); font-family: 宋体; font-size: 14px; line-height: 28px;"> //将视图设置为摄像头的叠加层</span> imagePicker.cameraOverlayView = overLayView;overLayView是自定义的,和普通的view一样,不过需要有个拍照按钮,当然也可以加背景进去。图为自己加了个按钮进去。
- (IBAction)takePicture:(id)sender{ imagePicker = [[UIImagePickerController alloc] init]; // If the device ahs a camera, take a picture, otherwise, // just pick from the photo library if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.showsCameraControls=NO;//禁用摄像头控件 //创建叠加层 UIView *overLayView=[[UIView alloc]initWithFrame:self.view.bounds]; UIImageView *crosshairs = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; crosshairs.frame = CGRectMake(self.view.center.x - 25, self.view.center.y - 25, 50, 50); crosshairs.image = [UIImage imageNamed:@"logo"]; crosshairs.alpha = 0.5f; crosshairs.contentMode = UIViewContentModeCenter; [overLayView addSubview:crosshairs];
<span style="color: rgb(51, 51, 51); font-family: 宋体; font-size: 14px; line-height: 28px; text-indent: 28px;"> //将视图设置为摄像头的叠加层</span> imagePicker.cameraOverlayView = overLayView; //在叠加视图上自定义一个拍照按钮 UIButton *takePhotoBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [takePhotoBtn setFrame:CGRectMake(74, 370, 178, 37)]; [takePhotoBtn setTitle:@"选取图片" forState:UIControlStateNormal]; [takePhotoBtn addTarget:self action:@selector(takePhoto:) forControlEvents:UIControlEventTouchUpInside]; [overLayView addSubview:takePhotoBtn]; } else { imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } imagePicker.allowsEditing = YES; imagePicker.delegate = self; [self flashModeOn]; [self cameraOriention]; // Place image picker on the screen [self presentViewController:imagePicker animated:YES completion:NULL];}- (IBAction)backgroundTapped:(id)sender{ [self.view endEditing:YES];}- (void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info{ NSString *oldKey = self.item.itemKey; // Did the item already have an image? if (oldKey) { // Delete the old image [[BNRImageStore sharedStore] deleteImageForKey:oldKey]; } UIImage *image; // Get picked image from info dictionary if (info[UIImagePickerControllerEditedImage]) { image =info[UIImagePickerControllerEditedImage]; } else { image = info[UIImagePickerControllerOriginalImage]; } // Store the image in the BNRImageStore for this key [[BNRImageStore sharedStore] setImage:image forKey:self.item.itemKey]; // Put that image onto the screen in our image view self.imageView.image = image; // Take image picker off the screen - // you must call this dismiss method [self dismissViewControllerAnimated:YES completion:NULL];}//闪光灯-(void)flashModeOn{ if (imagePicker.cameraFlashMode == UIImagePickerControllerCameraFlashModeAuto) { imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; } else { imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff; }}- (void)cameraOriention{ if (imagePicker.cameraDevice == UIImagePickerControllerCameraDeviceRear) { imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront; } else { imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear; }}- (void)takePhoto:(id)sender{ [imagePicker takePicture];}
第二个需要注意的是如何使用编辑的照片,
1,需要设定可编辑:<pre name="code" class="objc"> imagePicker.allowsEditing = YES;
2,需要选择编辑过的照片,(只能放大缩小)
<pre name="code" class="objc"> UIImage *image; // Get picked image from info dictionary if (info[UIImagePickerControllerEditedImage]) { image =info[UIImagePickerControllerEditedImage]; } else { image = info[UIImagePickerControllerOriginalImage]; }如果直接使用了,
UIImagePickerControllerEditedImage,而没有做第一步的话,那么程序就会崩溃。
0 0
- 自定义照相机界面之cameraOverlayView和UIImagePickerControllerEditedImage
- 自定义照相机拍照界面
- 自定义 照相机
- 自定义照相机
- 自定义照相机
- iOS之打开照相机拍照或者录像/打开手机的相册或者视频/视频压缩/自定义相机界面/照片或视频保存到相册
- Android自定义照相机实现
- Android自定义照相机注意事项
- 自定义的照相机视图
- android 自定义照相机
- iOS自定义照相机
- 自定义照相机官方指南
- iOS 自定义照相机
- 自定义安卓照相机
- Android自定义简易照相机
- 简易的自定义照相机
- Android 自定义照相机
- 自定义照相机(一)
- 最近公共祖先LCA离线算法
- 92 捣乱分子个数
- IOS异步网络处理
- poj2528 贴海报
- 93 求数组,左边的数都小于等于它,右边的数都大于等于它
- 自定义照相机界面之cameraOverlayView和UIImagePickerControllerEditedImage
- 手机短信发送案例
- DOS中FOR命令用法详解
- CodeForces 1B. Spreadsheets(模拟)
- 关于Redis的一些常识
- Memcached真的过时了吗
- PAE下的虚拟内存映射 分析
- LIBCURL教程(转)
- 93 长度大于=3的最长的等差数列