ios - Xamarin.iOS ZXing.Net.Mobile 条码扫描器
<p><p>我正在尝试将条形码扫描器功能添加到我的 xamarin.ios 应用中。我正在从 visual studio 进行开发,并且添加了来自 xamarin 组件商店的 Zxing.Net.Mobile 组件。</p>
<p>我已经按照示例中所示实现了它:</p>
<pre><code>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;
}
</code></pre>
<p>问题是,当我点击扫描按钮时,捕获 View 会正确显示,但如果我 try catch 条形码,则没有任何反应,而且扫描仪似乎无法识别任何条形码。</p>
<p>有人遇到过这个问题吗?我怎样才能让它发挥作用?</p>
<p>预先感谢您的帮助!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我回答过类似的问题<a href="https://stackoverflow.com/a/42678187/4286379" rel="noreferrer noopener nofollow">here</a> .由于默认相机分辨率设置得太低,我无法扫描条形码。这种情况的具体实现是:</p>
<pre><code>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);
};
</code></pre>
<p>然后是 <code>HandleCameraResolutionSelectorDelegate</code> 的定义:</p>
<pre><code>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 ;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - Xamarin.iOS ZXing.Net.Mobile 条码扫描器,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38994901/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38994901/
</a>
</p>
页:
[1]