Xamarin Forms - Zxing QR Scanner - How can you toggle the camera being used?

前提是你 提交于 2020-06-13 06:37:39

问题


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.

Is this possible using zxing for xamarin forms?

My options look like this:

code:

//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;

Setting:

ScannerView.Options.UseFrontCameraIfAvailable = true;

Does NOT change the camera. I can however do this

ScannerView = null;
CreateScannerView();
ScannerView.Options.UseFrontCameraIfAvailable = true;
ScannerView.IsScanning = true;

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.

Is switching the camera possible?


回答1:


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);


来源:https://stackoverflow.com/questions/47936023/xamarin-forms-zxing-qr-scanner-how-can-you-toggle-the-camera-being-used

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