使用gpuimage时遇到的问题

时间:2013-06-21 10:46:03

标签: iphone ios

我习惯于构建1个gpuimage成像应用程序。但是我遇到了一些问题。 首先是我选择前置摄像头和后置摄像头。点击几下按钮后,我的应用程序就会崩溃。 接下来的问题是我的相机图像显示拉长。在相机相反的方向之后。 谁能帮我解决这个问题? 谢谢

- (void)viewDidLoad     {
    [super viewDidLoad]; 
    self.wantsFullScreenLayout = YES;
    iFlash = 1;
    hasBlur = NO;
    cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0f, 0.0f, 1.0f, 0.75f)];
    filter = [[GPUImageRGBFilter alloc] init];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        [self setUpCamera];
    });

    //cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0f, 0.0f, 1.0f, 0.75f)];
    filter = [[GPUImageRGBFilter alloc] init];

    [[self navigationController] setNavigationBarHidden:YES animated:NO]; 
}

- (IBAction)rotateCameraPressed:(id)sender {
    hasBlur = NO;

    if(sttRotate == 0) {
        sttRotate = 1;
        [self removeAllTargets];
        [self setUpCamera];
    }
    else if(sttRotate == 1){
        [self removeAllTargets];        
        sttRotate = 0;
        [self setUpCamera];
    }
}

- (void)setUpCamera { 
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
    // Has camera

        if(sttRotate == 1) { 
            stillCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionFront];
        }
        else if(sttRotate == 0) {           
            stillCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];
        }

        stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
        runOnMainQueueWithoutDeadlocking(^{
            [stillCamera startCameraCapture];
            if([stillCamera.inputCamera hasFlash]){
                [self.flashToggleButton setEnabled:NO];
                [stillCamera.inputCamera lockForConfiguration:nil];
                if([stillCamera.inputCamera flashMode] == AVCaptureFlashModeOff){
                    [self.flashToggleButton setImage:[UIImage imageNamed:@"flash-off"] forState:UIControlStateNormal];
                }
                else if ([stillCamera.inputCamera flashMode] == AVCaptureFlashModeAuto){
                   [self.flashToggleButton setImage:[UIImage imageNamed:@"flash-auto"] forState:UIControlStateNormal];
                }
                else {
                [self.flashToggleButton setImage:[UIImage imageNamed:@"flash"] forState:UIControlStateNormal];
                }
                [stillCamera.inputCamera unlockForConfiguration];
                [self.flashToggleButton setEnabled:YES];
            }
            else {
                [self.flashToggleButton setEnabled:NO];
            }
            [self prepareFilter];
        });
    }
    else {
        // No camera 
        runOnMainQueueWithoutDeadlocking(^{
            [self prepareFilter];
        });
    }
}

0 个答案:

没有答案
相关问题