Xamarin Forms-Zxing QR Scanner-如何切换使用的相机? [英] Xamarin Forms - Zxing QR Scanner - How can you toggle the camera being used?
问题描述
当我开始使用Xamarian
形式的ScannerView
扫描条形码时,它会自动转到手机上的后置摄像头.
When I start scanning for barcodes using a ScannerView
in Xamarian
forms, it automatically goes to the back camera on the phone.
我想创建一个切换相机按钮,将相机从后向前切换,反之亦然.
I would like to make a toggle camera button that toggles the camera from back to front and vice versa.
使用xxing形式的xamarin可以做到吗?
Is this possible using zxing for xamarin forms?
我的选项如下:
代码:
//Set the scanner options.
ScannerView.Options = new ZXing.Mobile.MobileBarcodeScanningOptions()
{
UseNativeScanning = true,
AutoRotate = true,
PossibleFormats = new List<ZXing.BarcodeFormat>()
{
ZXing.BarcodeFormat.QR_CODE
},
TryHarder = true,
UseFrontCameraIfAvailable = false,
DelayBetweenContinuousScans = 2000
};
一旦我开始通过设置进行扫描
Once I start scanning by setting
ScannerView.IsScanning = true;
设置:
ScannerView.Options.UseFrontCameraIfAvailable = true;
请勿更换相机.但是我可以这样做
Does NOT change the camera. I can however do this
ScannerView = null;
CreateScannerView();
ScannerView.Options.UseFrontCameraIfAvailable = true;
ScannerView.IsScanning = true;
它有效.但是,摄像机视图会完全消失约2秒钟,然后再返回.当我为另一个应用程序的iOS
进行本机的Xcode
拍摄时,相机视图永不消失,只是翻转了相机.我期待这样的事情.
And it works. However the camera view completely disappears for about 2 seconds and then comes back. When I did it native Xcode
for iOS
for another app, the camera view never went away and just flipped cameras. I'm expecting something like that.
可以切换相机吗?
推荐答案
我不认为Zxing开始扫描后就可以在Zxing相机之间进行切换,因此必须事先选择并设置选项.
I don't think switching between cameras itself is possible with Zxing once it has started scanning so the option has to be chosen and set beforehand.
var options = new MobileBarcodeScanningOptions
{
AutoRotate = true,
UseNativeScanning = true,
TryHarder = true,
TryInverted = true,
UseFrontCameraIfAvailable = true
};
var scannedCode = await _scanner.Scan(options);
这篇关于Xamarin Forms-Zxing QR Scanner-如何切换使用的相机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!