/// <summary> /// <see cref="LabelReaderBase.GetFullTextFromImage(object)"/> /// </summary> /// <param name="image"></param> /// <returns></returns> public override Task <string> GetFullTextFromImageAsync(object image) { byte[] imageBytes = (byte[])image; TaskCompletionSource <string> taskCompletionSource = new TaskCompletionSource <string>(); StringBuilder stringBuilder = new StringBuilder(); using (Bitmap imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length)) using (global::Android.Gms.Vision.Frame frame = new global::Android.Gms.Vision.Frame.Builder().SetBitmap(imageBitmap).Build()) { SparseArray textArray = TextRecognizer.Detect(frame); List <string> valuesInOrder = OrderTextBlocks(textArray); foreach (string value in valuesInOrder) { stringBuilder.Append(value); } taskCompletionSource.SetResult(stringBuilder.ToString()); } return(taskCompletionSource.Task); }
/// <summary> /// <see cref=ILabelReader.GetRawBarcodeTextFromImageAsync(object)"/> /// </summary> /// <param name="image"></param> /// <returns></returns> public override Task <string> GetRawBarcodeTextFromImageAsync(object image) { byte[] imageBytes = (byte[])image; TaskCompletionSource <string> taskCompletionSource = new TaskCompletionSource <string>(); using (Bitmap imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length)) using (global::Android.Gms.Vision.Frame frame = new global::Android.Gms.Vision.Frame.Builder().SetBitmap(imageBitmap).Build()) { SparseArray barcodeArray = BarcodeDetector.Detect(frame); if (barcodeArray.Size() <= 0) { taskCompletionSource.SetResult(String.Empty); } else { Barcode qr = (Barcode)(barcodeArray.ValueAt(0)); taskCompletionSource.SetResult(qr.RawValue); } } return(taskCompletionSource.Task); }