private async void DetectBarcodeActionAsync(VisionImage image) { if (Configuration.IsScanning) { try { VisionBarcode[] barcodes = await barcodeDetector.DetectAsync(image); if (barcodes == null || barcodes.Length == 0) { return; } Console.WriteLine($"Successfully read barcode"); Configuration.IsScanning = false; if (_vibrationOnDetected) { SystemSound.Vibrate.PlayAlertSound(); } List <BarcodeResult> resultList = new List <BarcodeResult>(); foreach (var barcode in barcodes) { resultList.Add(new BarcodeResult { BarcodeType = Methods.ConvertBarcodeResultTypes(barcode.ValueType), DisplayValue = barcode.DisplayValue }); } OnDetected?.Invoke(resultList); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); } } }
public static async Task <List <BarcodeResult> > ScanFromImage(byte[] imageArray) { UIImage image = new UIImage(NSData.FromArray(imageArray)); var visionImage = new VisionImage(image); VisionImageMetadata metadata = new VisionImageMetadata(); VisionApi vision = VisionApi.Create(); VisionBarcodeDetector barcodeDetector = vision.GetBarcodeDetector(Configuration.BarcodeDetectorSupportFormat); VisionBarcode[] barcodes = await barcodeDetector.DetectAsync(visionImage); if (barcodes == null || barcodes.Length == 0) { return(new List <BarcodeResult>()); } List <BarcodeResult> resultList = new List <BarcodeResult>(); foreach (var barcode in barcodes) { resultList.Add(new BarcodeResult { BarcodeType = Methods.ConvertBarcodeResultTypes(barcode.ValueType), DisplayValue = barcode.DisplayValue }); } return(resultList); }
public static async Task <List <BarcodeResult> > ScanFromImage(byte[] imageArray) { UIImage image = new UIImage(NSData.FromArray(imageArray)); var visionImage = new VisionImage(image); VisionImageMetadata metadata = new VisionImageMetadata(); VisionApi vision = VisionApi.Create(); VisionBarcodeDetector barcodeDetector = vision.GetBarcodeDetector(Configuration.BarcodeDetectorSupportFormat); VisionBarcode[] barcodes = await barcodeDetector.DetectAsync(visionImage); if (barcodes == null || barcodes.Length == 0) { return(new List <BarcodeResult>()); } List <BarcodeResult> resultList = new List <BarcodeResult>(); foreach (var barcode in barcodes) { var points = barcode.CornerPoints.ToList().ConvertAll(nsvalue => nsvalue.PointFValue); resultList.Add(new BarcodeResult { BarcodeType = Methods.ConvertBarcodeResultTypes(barcode.ValueType), DisplayValue = barcode.DisplayValue, Points = points.Select(p => (p.X / (double)image.Size.Width, p.Y / (double)image.Size.Height)).ToList() });
/// <summary> /// <see cref="LabelReaderBase.GetRawBarcodeTextFromImageAsync(object)"/> /// </summary> /// <param name="image"></param> /// <returns></returns> public override async Task <string> GetRawBarcodeTextFromImageAsync(object image) { CoreMedia.CMSampleBuffer iOSImage = (CoreMedia.CMSampleBuffer)image; VisionImage visionImage = new VisionImage(iOSImage); visionImage.Metadata = new VisionImageMetadata { Orientation = GetOrientation() }; VisionApi api = VisionApi.Create(); VisionBarcodeDetector barcodeDetector = api.GetBarcodeDetector(new VisionBarcodeDetectorOptions(VisionBarcodeFormat.QRCode)); VisionBarcode[] barcodes = await barcodeDetector.DetectAsync(visionImage); if (barcodes.Length <= 0) { return(String.Empty); } return(barcodes.First().RawValue); }