【问题标题】:Live Camera Background iOS Objective-C Using UIImagePickerController?使用 UIImagePickerController 的实时相机背景 iOS Objective-C?
【发布时间】:2015-09-24 04:10:32
【问题描述】:

我的实时摄像头背景可以使用UIImagePickerController 类吗?

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

主页视图控制器中有两个按钮(按钮 1 用于照片,按钮 2 用于视频),但同时,我的背景是一个类似的相机。我已经成功实现了照片和视频功能。除了现场背景之外,所有内容都已完成。

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

我的视频和照片代码:

  1. 视频:

    -(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. 照片:

       -(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


    【解决方案1】:

    您可以使用 UIImagePickerController 的cameraOverlayView 属性。

    1. 创建一个 UIImagePickerController
    2. 用按钮配置视图(视图应该是清晰的背景色)
    3. 将视图设置为图像选择器的cameraOverlayView
    4. 目前的图像选择器

    【讨论】:

      【解决方案2】:

      您应该为此使用 AVCam。

      https://github.com/gabro/AVCam

      谢谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-11
        相关资源
        最近更新 更多