我在ios应用程序中使用zbar sdk。我想调暗相机闪光灯。 在ios文档中,我找到了AVCaptureDevice
- (BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError **)outError
在AVCaptureDevice类中,setTorchModeOnWithLevel函数将亮度级别设置为0-1。 在zbar sdk中,我在readerview类中找到了这个对象 我正在使用以下代码
ZBarReaderViewController *mReader = [[ZBarReaderViewController alloc] init];
mReader.showsZBarControls = NO;
mReader.showsHelpOnFail = NO;
mReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
mReader.readerDelegate = self;
// reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
mReader.supportedOrientationsMask = ZBarOrientationMaskAll;
CGRect cropRect = CGRectMake(0, 0, cameraView.frame.size.width , cameraView.frame.size.height);
mReader.view.frame = cropRect;
mReader.cameraOverlayView = [self setOverlayPickerView];
AVCaptureDevice *mDevice = mReader.readerView.device; //mReader.readerView.device returns object of AVCaptureDevice
当我尝试访问AVCaptureDevice函数时,它没有显示任何建议,当我手动编写它然后它给出错误。
[mDevice setTorchModeOnWithLevel:0.5 error:error];
如何使用AVCaptureDevice对象以便我可以设置闪光灯的暗淡级别?
答案 0 :(得分:0)
Zbar SDK中没有用于控制Flash灯级的API。你可以打开/关闭闪光灯。
答案 1 :(得分:0)
我正在调用以下给出错误的函数
[mDevice setTorchModeOnWithLevel:0.5 error:error];
错误的原因是我没有在构建设置中包含AVFoundation库。包括我的错误后解决 @rakeshNS我们可以使用
调暗zbar sdk灯光AVCaptureDevice *mDevice = mReader.readerView.device;
[mDevice setTorchModeOnWithLevel:0.5 error:nil];
感谢大家
答案 2 :(得分:-1)
我正在使用下面的代码希望它可以帮助你:)
reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.readerView.torchMode = 2;
reader.showsZBarControls = FALSE;
reader.tracksSymbols = YES;
[reader.scanner setSymbology: ZBAR_ISBN13
config: ZBAR_CFG_ENABLE
to: 0];
reader.readerView.zoom = 1.0;
reader.cameraOverlayView = [self setLayoutView];
if([[defaults valueForKey:@"flashLight1"] isEqualToString:@"off"] )
reader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
else
reader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;