带有TryInverted颜色选项的ZXing,DataMatrix Reader似乎不适用于iOs(Xamarin.Forms)

时间:2018-06-08 17:07:48

标签: c# ios xamarin.forms datamatrix zxing.net

我正在使用Xamarin.Forms和Visual Studio开发一个App,我也尝试使用ZXing.Net.Mobile和ZXing.Net.Mobile.Forms Nuget Packages来扫描DataMatrix。

默认情况下一切正常,除非使用反色打印DataMatrix。这就是我尝试使用TryInverted选项的原因,但似乎此选项不适用于Apple设备。

事实上,使用Android我的应用程序即使使用反转颜色也可以检测到DataMatrix,而iPhone 5S则不能,只有当颜色没有反转时才能检测到。 (我很确定,因为我试图在两种配置中使用相同的DataMatrix,反色而不是)。以下是我的代码,

var scan = DependencyService.Get<IDScan>();

var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
options.TryInverted = true;
options.TryHarder = true; /* Don't really know if it's needed ?*/
options.AutoRotate = true; 
options.PureBarcode = false; /* Don't really know what is it ?*/

options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
  ZXing.BarcodeFormat.DATA_MATRIX, ZXing.BarcodeFormat.QR_CODE
};

var result = await scan.GetResult(options);

if (result != null)
{
    await App.Current.MainPage.DisplayAlert(
               "Scan result",
               "Format :" + result.BarcodeFormat +
               "\nNumBits : " + result.NumBits +
               "\nValue : " + result.Text,
               "OK"
    );
}

我的iOs ScanActivity获得结果和扫描仪,

public class ScanActivity : IDScan
{
    ZXing.Mobile.MobileBarcodeScanner scanner;

    public ScanActivity()
    {
        Debug.WriteLine("Scan Android1");
        var window = UIKit.UIApplication.SharedApplication.KeyWindow;
        var vc = window.RootViewController;
        while (vc.PresentedViewController != null)
        {
            vc = vc.PresentedViewController;
        }
        scanner = new ZXing.Mobile.MobileBarcodeScanner(vc);

    }

    public ZXing.Mobile.MobileBarcodeScanner GetScanner()
    {
        return scanner;
    }

    public async Task<ZXing.Result> GetResult(ZXing.Mobile.MobileBarcodeScanningOptions options)
    {
        var result = await scanner.Scan(options,true);
        return result;
    }
}

0 个答案:

没有答案