简体   繁体   English

实时摄像机背景iOS Objective-C是否使用UIImagePickerController?

[英]Live Camera Background iOS Objective-C Using UIImagePickerController?

Is it possible to use UIImagePickerController class for my live camera background? 是否可以将UIImagePickerController类用于实时摄影机背景?

My App uses UIImagepickercontroller for capturing images and video. 我的应用程序使用UIImagepickercontroller捕获图像和视频。 My design is like this: 我的设计是这样的:

Two buttons (button 1 for Photo, button 2 for Video) in Home View Controller, but at the same time, my background is a like camera. Home View Controller中有两个按钮(“照片”按钮1,“视频”按钮2),但是同时,我的背景就像一台照相机。 I have successfully implemented the photo and video function. 我已经成功实现了照片和视频功能。 All are complete except for the live background. 除现场背景外,所有内容均完整。

I already tried this: Setting a background image/view to live camera view? 我已经尝试过: 将背景图像/视图设置为实时摄像机视图? using AVFoundation. 使用AVFoundation。 But it makes the camera load so slow. 但这会使摄像机加载速度太慢。 And sometimes the background freezes. 有时背景会冻结。

My code for video and photo: 我的视频和照片代码:

  1. VIDEO: 视频:

     -(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]; } 
  2. PHOTO: 照片:

      -(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: Can someone help me with code format? PS:有人可以在代码格式方面帮助我吗?

You can use cameraOverlayView property of of UIImagePickerController. 您可以使用UIImagePickerController的cameraOverlayView属性。

  1. Create a UIImagePickerController 创建一个UIImagePickerController
  2. Configure the view with buttons(view should be clear background color) 使用按钮配置视图(视图应为清晰的背景色)
  3. Set the view as cameraOverlayView of the image picker 将视图设置为图像选择器的cameraOverlayView
  4. Present imagepicker 目前的图像选择器

You should use AVCam for this. 您应该为此使用AVCam。

https://github.com/gabro/AVCam https://github.com/gabro/AVCam

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM