我怎样才能做到这一点?
我阅读了文档并发现我需要使用AVCaptureFlashMode
但我无法弄清楚2如何使用它?
任何帮助,将不胜感激.
更新了以下代码.谢谢SIF!
NSError* error = nil; NSLog(@"Setting up LED"); if([captDevice hasTorch] == NO) { NSLog(@"Error: This device doesnt have a torch"); } if([captDevice isTorchModeSupported:AVCapturetorchModeOn] == NO) { NSLog(@"Error: This device doesnt support AVCapturetorchModeOn"); } AVCaptureSession* captureSession = [[AVCaptureSession alloc] init]; AVCaptureDeviceinput* vIDeoinput = [[AVCaptureDeviceinput alloc] initWithDevice:captDevice error:&error]; AVCaptureVIDeoDataOutput* vIDeoOutput = [[AVCaptureVIDeoDataOutput alloc] init]; if (vIDeoinput && vIDeoOutput) { [captureSession addinput:vIDeoinput]; [captureSession addOutput:vIDeoOutput]; if([captDevice lockForConfiguration:&error]) { if (flag == YES) { captDevice.torchMode = AVCapturetorchModeOn; } else { captDevice.torchMode = AVCapturetorchModeOff; } [captDevice unlockForConfiguration]; } else { NSLog(@"Could not lock device for config error: %@",error); } [captureSession startRunning]; } else { NSLog(@"Error: %@",error); }
你怎么把它关掉?
解决方法AVCaptureDevice* d = nil;// find a device by positionNSArray* allDevices = [AVCaptureDevice devices];for (AVCaptureDevice* currentDevice in allDevices) { if (currentDevice.position == AVCaptureDevicepositionBack) { d = currentDevice; }}// at this point,d may still be nil,assuming we found something we like....NSError* err = nil;BOol lockAcquired = [d lockForConfiguration:&err];if (!lockAcquired) { // log err and handle...} else { // flip on the flash mode if ([d hasFlash] && [d isFlashModeSupported:AVCaptureFlashModeOn] ) { [d setFlashMode:AVCaptureFlashModeOn]; } [d unlockForConfiguration];}总结
以上是内存溢出为你收集整理的cocoa – 如何使用AVCaptureFlashMode全部内容,希望文章能够帮你解决cocoa – 如何使用AVCaptureFlashMode所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)