2015-03-07 6 views
0

Я уже давно работаю над проектом, и я пришел к одной вещи, над которой хочу по-настоящему разобраться, что я не смог понять.Фронт Яркость вспышки iPhone

В приложении, когда вы делаете переднюю фотографию, я бы хотел, чтобы передняя вспышка делала изображение ярче.

Я использую пользовательскую камеру AVCaptureSession, это полный экран. Вот код, который делает вспышку, только картина не ярче вообще.

//Here is the code for a front flash on the picture button press. It does flash, just doesn't help. 
UIWindow* wnd = [UIApplication sharedApplication].keyWindow; 
UIView *v = [[UIView alloc] initWithFrame: CGRectMake(0, 0, wnd.frame.size.width, wnd.frame.size.height)]; 
[wnd addSubview: v]; 
v.backgroundColor = [UIColor whiteColor]; 
[UIView beginAnimations: nil context: nil]; 
[UIView setAnimationDuration: 1.0]; 
v.alpha = 0.0f; 
[UIView commitAnimations]; 

//imageView is just the actual view the the cameras image fills. 
imageView.hidden = NO; 
AVCaptureConnection *videoConnection = nil; 
for (AVCaptureConnection *connection in stillImageOutput.connections) { 
    for(AVCaptureInputPort *port in [connection inputPorts]) { 
     if ([[port mediaType] isEqual:AVMediaTypeVideo]) { 
      videoConnection = connection; 
      break; 
     } 
    }if (videoConnection) { 
     break; 
    } 

} [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { 
    if (imageDataSampleBuffer != NULL) { 
     imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; 
     UIImage *thePicture = [UIImage imageWithData:imageData]; 
     self.imageView.image = thePicture; 
//After the picture is on the screen, I just make sure some buttons are supposed to be where they are supposed to be. 
     saveButtonOutlet.hidden = NO; 
     saveButtonOutlet.enabled = YES; 
     diaryEntryOutlet.hidden = YES; 
     diaryEntryOutlet.enabled = NO; 
    } 

}]; 

} 
+0

Почему вы установка альфа в 0 (прозрачные)? – Paulw11

+0

@ Paulw11 да, иначе белое окно останется белым навсегда. –

+0

Почему бы не просто установить цвет фона на 'clearColor'? Вы уверены, что ваш белый экран правильно синхронизирован с вашим захватом изображения? – Paulw11

ответ

1

Перед съемкой необходимо установить белый экран, дождаться завершения захвата и затем удалить белый экран в блоке завершения.

Вы должны также послать захват после короткой задержки, чтобы обеспечить экран побелел -

UIWindow* wnd = [UIApplication sharedApplication].keyWindow; 
UIView *v = [[UIView alloc] initWithFrame: CGRectMake(0, 0, wnd.frame.size.width, wnd.frame.size.height)]; 
[wnd addSubview: v]; 
v.backgroundColor = [UIColor whiteColor]; 

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 
    [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { 
     if (imageDataSampleBuffer != NULL) { 
      imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; 
      UIImage *thePicture = [UIImage imageWithData:imageData]; 

      dispatch_async(dispatch_get_main_queue(), ^{ 
       self.imageView.image = thePicture; 
       [v removeFromSuperview]; 
      }); 
     } 
     //After the picture is on the screen, I just make sure some buttons are supposed to be where they are supposed to be. 
     saveButtonOutlet.hidden = NO; 
     saveButtonOutlet.enabled = YES; 
     diaryEntryOutlet.hidden = YES; 
     diaryEntryOutlet.enabled = NO; 
    }]; 
}]; 
+0

Итак, я добавил это в свою программу, и я получаю ошибку выражения в IBAction ниже. Я собираюсь пройти и проверить, не хватает ли мне скобки или чего-то еще. –

+0

Неисправна замыкающая скобка для 'if (imageDataSampleBuffer! = Nil)' – Paulw11

+0

. Я все еще получаю ту же ошибку, теперь в этом блоке кода. Я продолжаю идти, хотя выясняется, что чего-то не хватает. Я получаю _Осмотренный идентификатор '(' _ и в той же строке _Expected ']' _. Линией, о которой я говорю, является последний '}];' –