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