I am developing an App using Xamarin.Forms and Visual Studio, and I also try to use ZXing.Net.Mobile and ZXing.Net.Mobile.Forms Nuget Packages to scan DataMatrix.
By default everything works fine, except when DataMatrix are printed using inverted colours. That's why I've tried to use TryInverted option, but It seems that this option doesn't work with Apple devices.
Indeed, using Android my app is able to detect DataMatrix even with Inverted colors and iPhone 5S is not, only when colours are not inverted. (I'm pretty sure because I've tried to use the same DataMatrix in both configurations, inverted colours and not). Below is my code,
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"
);
}
And my iOs ScanActivity to get result and scanner,
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;
}
}