How can i perform a flash like the native camera app performs one? I've found the following code to turn on the light, but i need to take a flash-shot.
if(self.videoDevice.hasTorch) {
[self.videoDevice lockForConfiguration:nil];
[self.videoDevice setTorchModeOnWithLevel: 1.0 error: nil];
[self.videoDevice unlockForConfiguration];
}
Try this one. Seems like same thing you are expecting
http://iosdevelopertips.com/camera/flashlight-application-using-the-iphone-led.html
您必须将TorchLevel设置在0.0到1.0之间,然后在非常小的间隔内再次设置为0.0。
- (BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError **)outError
Try this code:
- (void)turnOnCamerFlash
{
if (NSClassFromString(@"AVCaptureDevice") != nil)
{
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch])
{
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn];
[device unlockForConfiguration];
}
}
}
It seams that there is no flash-function in there, so the (only?) possibility to perform a flash is to use a timer.
- (IBAction)doFlash:(id)sender {
if(self.videoDevice.hasTorch) {
flashCounter = 0;
[NSTimer scheduledTimerWithTimeInterval: 0.1
target:self
selector:@selector(flashLightTicker:)
userInfo:nil
repeats: YES];
}
}
- (void)flashLightTicker:(id)sender {
[self.videoDevice lockForConfiguration:nil];
if(flashCounter == 0) {
[self.videoDevice setTorchModeOnWithLevel: 0.1 error: nil];
}
if(flashCounter == 5) {
[self.videoDevice setTorchMode: AVCaptureTorchModeOff];
}
if(flashCounter == 7) {
[self.videoDevice setTorchModeOnWithLevel: AVCaptureMaxAvailableTorchLevel error: nil];
}
if(flashCounter >= 10) {
[self.videoDevice setTorchMode: AVCaptureTorchModeOff];
[sender invalidate];
}
[self.videoDevice unlockForConfiguration];
flashCounter++;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.