我正在尝试将条形码扫描器功能添加到我的 xamarin.ios 应用中。我正在从 visual studio 进行开发,并且添加了来自 xamarin 组件商店的 Zxing.Net.Mobile 组件。
我已经按照示例中所示实现了它:
ScanButton.TouchUpInside += async (sender, e) => {
//var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
//options.AutoRotate = false;
//options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
// ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
//};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
//scanner.TopText = "Hold camera up to barcode to scan";
//scanner.BottomText = "Barcode will automatically scan";
//scanner.UseCustomOverlay = false;
scanner.FlashButtonText = "Flash";
scanner.CancelButtonText = "Cancel";
scanner.Torch(true);
scanner.AutoFocus();
var result = await scanner.Scan(true);
HandleScanResult(result);
};
void HandleScanResult(ZXing.Result result)
{
if (result != null && !string.IsNullOrEmpty(result.Text))
TextField.Text = result.Text;
}
问题是,当我点击扫描按钮时,捕获 View 会正确显示,但如果我 try catch 条形码,则没有任何反应,而且扫描仪似乎无法识别任何条形码。
有人遇到过这个问题吗?我怎样才能让它发挥作用?
预先感谢您的帮助!
我回答过类似的问题here .由于默认相机分辨率设置得太低,我无法扫描条形码。这种情况的具体实现是:
ScanButton.TouchUpInside += async (sender, e) => {
var options = new ZXing.Mobile.MobileBarcodeScanningOptions {
CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
.
.
.
scanner.AutoFocus();
//call scan with options created above
var result = await scanner.Scan(options, true);
HandleScanResult(result);
};
然后是 HandleCameraResolutionSelectorDelegate
的定义:
CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
{
//Don't know if this will ever be null or empty
if (availableResolutions == null || availableResolutions.Count < 1)
return new CameraResolution () { Width = 800, Height = 600 };
//Debugging revealed that the last element in the list
//expresses the highest resolution. This could probably be more thorough.
return availableResolutions [availableResolutions.Count - 1];
}
关于ios - Xamarin.iOS ZXing.Net.Mobile 条码扫描器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38994901/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) | Powered by Discuz! X3.4 |