2

我习惯于构建 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];
        });
    }
}
4

0 回答 0