我正在尝试使用Xamarin和ZXing实现条形码扫描应用。不幸的是,iPhone和iPad上的前置摄像头扫描效果不佳。任何建议或帮助赞赏
答案 0 :(得分:0)
您的InitializeScanner方法可以执行如下扫描程序初始化并调用开始扫描,在我的情况下,我想支持条形码和QR码。如果您不想支持,可以删除扫描选项QRCode。 当扫描程序识别代码并返回唯一字符串时,初始化时会调用回调。 扫描仪选项具有属性UseFrontCameraIfAvailable
var mobileBarcodeScanningOptions= new ZXing.Mobile.MobileBarcodeScanningOptions();
mobileBarcodeScanningOptions.UseFrontCameraIfAvailable = true;
mobileBarcodeScanningOptions.PossibleFormats = new List<ZXing.BarcodeFormat>() {
ZXing.BarcodeFormat.CODE_128,
ZXing.BarcodeFormat.CODE_93,
ZXing.BarcodeFormat.CODE_39,
ZXing.BarcodeFormat.PDF_417,
ZXing.BarcodeFormat.QR_CODE
};
mobileBarcodeScanningOptions.AutoRotate = false;
mobileBarcodeScanningOptions.TryHarder = true;
mobileBarcodeScanningOptions.TryInverted = false;
var scanview = new ZXingScannerView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height)) { }
scanview.AutoFocus();
//code to add your scanview in your main view
scanview.StartScanning(MyScanResultHandler, mobileBarcodeScanningOptions);
//After scanning code, scanner callbacks below method
private void MyScanResultHandler(Result obj)
{
if (obj != null)
{
//obj.Text gives you value of code in string which you can use further in your application
}
}