使用 ZBarSDK 时 iPhone 相机失去自动对焦功能
我正在开发一个应用程序,用户可以选择是否要扫描条形码或拍摄某物的照片。 为了拍照,我像往常一样使用 UIImagePickerController
。 为了扫描条形码,我使用 ZbarSDK 1.2 ZBarReaderViewController
。
拍照时一切都很完美。 扫描条形码时: 如果您启动应用程序并在拍照之前扫描条形码,它也可以完美运行。
但是,如果您拍照,然后返回并尝试扫描条形码,则相机会失去自动对焦功能,并且无法扫描条形码。
总结一下:
开始->扫描-> 自动对焦工作
开始->拍照 ->返回->扫描-> 自动对焦不起作用
这就是我初始化条形码扫描仪的方式:
-(ZBarReaderViewController *) barcodeScanner
{
if (nil == _barcodeScanner)
{
_barcodeScanner = [ZBarReaderViewController new];
_barcodeScanner.readerDelegate = self;
_barcodeScanner.cameraMode = ZBarReaderControllerCameraModeSampling;
_barcodeScanner.sourceType = UIImagePickerControllerSourceTypeCamera;
}
return _barcodeScanner;
}
有什么想法吗?
I'm working on an app that the user can select if he wants to scan a barcode or take a picture of something.
For taking a picture I'm using the UIImagePickerController
as usual.
For scanning barcode I'm using the ZbarSDK 1.2 ZBarReaderViewController
.
When taking a picture everything works perfect.
When scanning a barcode:
If you start the app and scan a barcode before taking a picture, it's also works perfect.
But is you take a picture, and then go back and try to scan a barcode, the camera loses the auto-focus and it's just impossible to scan a barcode.
To summarize:
Start -> Scan -> Auto focus working
Start -> Take Photo -> Back -> Scan -> Auto focus not working
This is how I initialize the barcode scanner:
-(ZBarReaderViewController *) barcodeScanner
{
if (nil == _barcodeScanner)
{
_barcodeScanner = [ZBarReaderViewController new];
_barcodeScanner.readerDelegate = self;
_barcodeScanner.cameraMode = ZBarReaderControllerCameraModeSampling;
_barcodeScanner.sourceType = UIImagePickerControllerSourceTypeCamera;
}
return _barcodeScanner;
}
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在加载 ZBarReaderViewController 之前,请确保释放 UIImagePickerController,在加载 UIImagePickerController 之前,请确保释放 ZBarReaderViewController。
我花了几天时间才弄清楚为什么我总是失去集中注意力的能力,结果发现我没有释放东西。对于其他偶然发现这个答案的人...您一次只能有 1 个 AVCaptureSession,否则事情会变得很混乱,您会失去集中注意力的能力。 ZBarReaderViewController 使用 AVCaptureSession,因此请确保在初始化新的 AVCaptureSession 之前释放它。
Before loading up ZBarReaderViewController make sure you release UIImagePickerController, and before you load up UIImagePickerController make sure you release ZBarReaderViewController.
It took me days to figure out why i kept losing the ability to focus, and turns out that i wasn't releasing things. For others stumbling onto this answer... You can only have 1 AVCaptureSession at a time otherwise things get screwy and you lose the ability to focus. ZBarReaderViewController uses AVCaptureSession so make sure you release it before you initialize a new AVCaptureSession.
我们在使用 Zbar 时遇到了同样的问题,我们通过在关闭模型视图之前延迟 2 秒来解决它。
We were facing same issue with Zbar, we solved it by putting a 2 sec delay before dismissing model view.
我会更深入地研究你拍照的实现。尝试检查拍照完成后是否正确关闭资源。我不认为 zBar 的实现与此有任何关系......
I would look deeper into your implementation of taking picture. Try to check if you close the resource correctly when done taking the photo. I don't think zBar implementation got anything to do with it...