如何使用 AVCaptureFlashMode
我正在制作一个应用程序,可以将图像拼接成全景场景。我希望能够以编程方式打开 iPhone 4 上的闪光灯 LED。
我该怎么做?
我阅读了文档并发现我需要使用 AVCaptureFlashMode
但我不知道 2 如何使用它?
任何帮助将不胜感激。
更新了下面的代码。谢谢西弗!
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); }
如何将其关闭?
I'm making an app to allow me to stitch images together into a panoramic scene. I want to be able to turn the Flash LED on the iPhone 4 programatically.
How can I do this?
I read the documentation and discovered that I need to use AVCaptureFlashMode
but I can't figure out how 2 use it?
any help would be appreciated.
Updated Code below. Thanks 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); }
How do you turn it off?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)