Live Camera Background iOS Objective-C使用UIImagePickerController?

时间:2015-09-24 04:10:33

标签: ios objective-c uiimagepickercontroller

是否可以将UIImagePickerController课程用于我的实时相机背景?

我的应用使用UIImagepickercontroller来捕获图像和视频。我的设计是这样的:

Home View Controller中的两个按钮(Photo的按钮1,Video的按钮2),但同时,我的背景就像一个相机。我已经成功实现了照片和视频功能。除了现场背景外,所有内容都已完成。

我已经尝试过这个:Setting a background image/view to live camera view? 使用AVFoundation。但它使相机负载变得如此缓慢。有时背景会冻结。

我的视频和照片代码:

  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];
        }
    
    }
    
  3. PS:有人可以用代码格式帮助我吗?

2 个答案:

答案 0 :(得分:0)

您可以使用UIImagePickerController的cameraOverlayView属性。

  1. 创建UIImagePickerController
  2. 使用按钮配置视图(视图应为透明背景颜色)
  3. 将视图设置为图像选取器的cameraOverlayView
  4. 目前的imagepicker

答案 1 :(得分:0)

你应该使用AVCam。

https://github.com/gabro/AVCam

由于