How to set camera flash light level in zbar sdk

吃可爱长大的小学妹 提交于 2019-12-11 19:19:19

问题


I am using zbar sdk in my ios app. I want to dim the camera flash light. In ios documentation I have found AVCaptureDevice

- (BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError **)outError

In AVCaptureDevice class setTorchModeOnWithLevel function sets the light level between 0-1. In zbar sdk I have found this object in readerview class I am using following code

    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

When I try to access AVCaptureDevice functions it show nothing in suggestion and when I write it manually then it give error.

[mDevice setTorchModeOnWithLevel:0.5 error:error];

How I can use AVCaptureDevice object so that I can set the dim level of flash light??


回答1:


There is no API in Zbar SDK to control Flash light level. You just can Turn On/Turn Off the flash.




回答2:


I was calling following function which give error

[mDevice setTorchModeOnWithLevel:0.5 error:error];

The reason of error was that I have not included AVFoundation library in build setting. After including my error resolves @rakeshNS we can dim the zbar sdk light by using

AVCaptureDevice *mDevice = mReader.readerView.device;
[mDevice setTorchModeOnWithLevel:0.5 error:nil];

Thanks to everybody




回答3:


I am using below code hope it can help you :)

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;


来源:https://stackoverflow.com/questions/18711867/how-to-set-camera-flash-light-level-in-zbar-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!