0

我正在使用 Xamarin.Forms 和 Visual Studio 开发应用程序,并且我还尝试使用 ZXing.Net.Mobile 和 ZXing.Net.Mobile.Forms Nuget 包来扫描 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;
    }
}
4

0 回答 0