【发布时间】:2015-09-24 04:10:32
【问题描述】:
我的实时摄像头背景可以使用UIImagePickerController 类吗?
我的应用程序使用UIImagepickercontroller 来捕获图像和视频。我的设计是这样的:
主页视图控制器中有两个按钮(按钮 1 用于照片,按钮 2 用于视频),但同时,我的背景是一个类似的相机。我已经成功实现了照片和视频功能。除了现场背景之外,所有内容都已完成。
我已经尝试过了:Setting a background image/view to live camera view? 使用 AVFoundation。但它使相机加载如此缓慢。有时背景会冻结。
我的视频和照片代码:
-
视频:
-(IBAction)videoActionButton:(id)sender { NSLog(@"video button has been clicked"); // [self dismissViewControllerAnimated:NO completion:nil]; // VideoViewController *videoViewController = [[VideoViewController alloc] initWithNibName:nil bundle:nil]; // [self.navigationController pushViewController:videoViewController animated:YES]; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { videoRecorder = [[UIImagePickerController alloc] init]; videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera; videoRecorder.delegate = self; NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; NSArray *videoMediaTypesOnly = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF contains %@)", @"movie"]]; if ([videoMediaTypesOnly count] == 0) //Is movie output possible? { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Sorry but your device does not support video recording" delegate:nil cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:nil]; [actionSheet showInView:[[self view] window]]; // [actionSheet autorelease]; } else { //Select front facing camera if possible if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) videoRecorder.cameraDevice = UIImagePickerControllerCameraDeviceFront; videoRecorder.mediaTypes = videoMediaTypesOnly; videoRecorder.videoQuality = UIImagePickerControllerQualityTypeMedium; videoRecorder.videoMaximumDuration = 600; //Specify in seconds (600 is default) [self presentViewController:videoRecorder animated:YES completion:nil]; } // [videoRecorder release]; } else { //No camera is availble } // [imagePickerController release]; // UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // UINavigationController *videoViewController = [sb instantiateViewControllerWithIdentifier:@"videoViewController"]; // [self presentViewController:videoViewController animated:NO completion:NULL]; } -
照片:
-(IBAction)photoActionButton:(id)sender { NSLog(@"photo button has been clicked"); photoButtonClicked = true; UIImagePickerControllerSourceType type = UIImagePickerControllerSourceTypeCamera; if([UIImagePickerController isSourceTypeAvailable:type]){ UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.allowsEditing = NO; picker.delegate = self; picker.sourceType = type; [self presentViewController:picker animated:YES completion:nil]; } }
PS:有人可以帮我解决一下代码格式吗?
【问题讨论】:
标签: ios objective-c uiimagepickercontroller