我正在制作一个应用程序,允许我将图像拼接到一个全景场景中。我希望能够以编程方式打开iPhone 4上的Flash LED。如何使用AVCaptureFlashMode
我该怎么做?
我阅读文档,发现我需要使用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); }
如何关闭它?
请在这里看到我的回答对未来如何开/关切换参考:http://stackoverflow.com/questions/3190034/turn-on-torch-flash-on-iphone-4/3367424# 3367424 – iwasrobbed 2010-07-29 22:20:22