Ejemplo n.º 1
0
        /// <summary>
        /// Returns the zxing reader class for the current specified ScanMode.
        /// </summary>
        /// <returns></returns>
        internal static com.google.zxing.Reader GetReader(BarcodeFormat format)
        {
            Dictionary <object, object> zxingHints
                = new Dictionary <object, object>()
                {
                { DecodeHintType.TRY_HARDER, true }
                };

            com.google.zxing.Reader r;
            switch (format.Name)
            {
            case "CODE_128":
                r = new com.google.zxing.oned.Code128Reader();
                break;

            case "CODE_39":
                r = new com.google.zxing.oned.Code39Reader();
                break;

            case "EAN_13":
                r = new com.google.zxing.oned.EAN13Reader();
                break;

            case "EAN_8":
                r = new com.google.zxing.oned.EAN8Reader();
                break;

            case "ITF":
                r = new com.google.zxing.oned.ITFReader();
                break;

            case "UPC_A":
                r = new com.google.zxing.oned.UPCAReader();
                break;

            case "UPC_E":
                r = new com.google.zxing.oned.UPCEReader();
                break;

            case "QR_CODE":
                r = new com.google.zxing.qrcode.QRCodeReader();
                break;

            case "DATAMATRIX":
                r = new com.google.zxing.datamatrix.DataMatrixReader();
                break;

            case "ALL_1D":
                r = new com.google.zxing.oned.MultiFormatOneDReader(zxingHints);
                break;

            //Auto-Detect:
            case "UPC_EAN":
            default:
                r = new com.google.zxing.oned.MultiFormatUPCEANReader(zxingHints);
                break;
            }
            return(r);
        }
Ejemplo n.º 2
0
        public bool TryToRecognizeBarcode(WriteableBitmap wb, out string barCode)
        {
            // set some recognition settings
            var zxhints = new Dictionary<object, object>()
                {
                    { DecodeHintType.TRY_HARDER, true },
                    { DecodeHintType.POSSIBLE_FORMATS, new List<Object>() { BarcodeFormat.UPC_A, BarcodeFormat.UPC_E } }
                };

            // create reader instance
            var reader = new com.google.zxing.oned.MultiFormatUPCEANReader(zxhints);
            return TryToRecognize(wb, reader, zxhints, out barCode);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the zxing reader class for the current specified ScanMode.
        /// </summary>
        /// <returns></returns>
        internal static com.google.zxing.Reader GetReader(BarcodeFormat format)
        {
            Dictionary<object, object> zxingHints
                = new Dictionary<object, object>() { { DecodeHintType.TRY_HARDER, true } };
            com.google.zxing.Reader r;
            switch (format.Name)
            {
                case "CODE_128":
                    r = new com.google.zxing.oned.Code128Reader();
                    break;
                case "CODE_39":
                    r = new com.google.zxing.oned.Code39Reader();
                    break;
                case "EAN_13":
                    r = new com.google.zxing.oned.EAN13Reader();
                    break;
                case "EAN_8":
                    r = new com.google.zxing.oned.EAN8Reader();
                    break;
                case "ITF":
                    r = new com.google.zxing.oned.ITFReader();
                    break;
                case "UPC_A":
                    r = new com.google.zxing.oned.UPCAReader();
                    break;
                case "UPC_E":
                    r = new com.google.zxing.oned.UPCEReader();
                    break;
                case "QR_CODE":
                    r = new com.google.zxing.qrcode.QRCodeReader();
                    break;
                case "DATAMATRIX":
                    r = new com.google.zxing.datamatrix.DataMatrixReader();
                    break;

                case "ALL_1D":
                    r = new com.google.zxing.oned.MultiFormatOneDReader(zxingHints);
                    break;
                
                //Auto-Detect:
                case "UPC_EAN":
                default:
                    r = new com.google.zxing.oned.MultiFormatUPCEANReader(zxingHints);
                    break; 
            }
            return r;
        }
Ejemplo n.º 4
0
        private void ProcessImage(BarcodeCaptureResult captureResults) {
            captureResults.State = CaptureState.Processing;
            try {
                bool bIsReady = captureResults.isReadyForProcessing.WaitOne(3000);
                if (!bIsReady) {
                    captureResults.State = CaptureState.UnknownError;
                    captureResults.ErrorMessage = "Error: Timeout waiting for images to be processed. Please try again or send issue report using app bar.";
                    return;
                }


                if (captureResults.VGABarcodeImage != null)
                {
                    var wb = captureResults.VGABarcodeImage;

                    //Code from: btnReadTag_Click in "SLZXingQRSample\SLZXingQRSample\SLZXingSample\MainPage.xaml.vb"
                    var qrRead = new com.google.zxing.oned.MultiFormatUPCEANReader(zxingHints); ; // new com.google.zxing.qrcode.QRCodeReader();
                    var luminiance = new RGBLuminanceSource(wb, 640, 480);
                    var binarizer = new com.google.zxing.common.HybridBinarizer(luminiance);
                    var binBitmap = new com.google.zxing.BinaryBitmap(binarizer);
                    var results = qrRead.decode(binBitmap, zxingHints); //NOTE: will throw exception if cannot decode image.
                    captureResults.BarcodeText = results.Text;
                    captureResults.State = CaptureState.Success;

                    BarcodeCaptured.Invoke(captureResults);
                    //captureResults.ProcessValue();
                }
                else {
                    captureResults.State = CaptureState.UnknownError;
                    captureResults.ErrorMessage = "Cannot process image: invalid or null BitmapImage.";
                }
            }
            catch (Exception ex) {
                captureResults.ExceptionThrown = ex;
                if (ex is com.google.zxing.ReaderException) {
                    captureResults.ErrorMessage = "Error: Cannot decode barcode image. Please make sure scan mode is correct and try again.";
                    captureResults.State = CaptureState.ScanFailed;
                }
                else {
                    Debug.WriteLine("Error: " + ex.ToString());
                    captureResults.ErrorMessage = String.Format("Barcode Library Processing Error: {0}\r\n{1}", ex.GetType(), ex.Message);
                    captureResults.State = CaptureState.UnknownError;
                }
            }
            finally
            {
                lock (_resultTaskLock)
                {
                    _resultTask = null;
                }
            }
            
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the zxing reader class for the current specified ScanMode.
        /// </summary>
        /// <returns></returns>
        public static com.google.zxing.Reader GetReader()
        {
            com.google.zxing.Reader r;
            switch (WP7BarcodeManager.ScanMode.Name)
            {
                case "CODE_128":
                    r  = new com.google.zxing.oned.Code128Reader();
                    break;
                case "CODE_39":
                    r  = new com.google.zxing.oned.Code39Reader();
                    break;
                case "EAN_13":
                    r  = new com.google.zxing.oned.EAN13Reader();
                    break;
                case "EAN_8":
                    r  = new com.google.zxing.oned.EAN8Reader();
                    break;
                case "ITF":
                    r  = new com.google.zxing.oned.ITFReader();
                    break;
                case "UPC_A":
                    r  = new com.google.zxing.oned.UPCAReader();
                    break;
                case "UPC_E":
                    r  = new com.google.zxing.oned.UPCEReader();
                    break;
                case "QR_CODE":
                    r  = new com.google.zxing.qrcode.QRCodeReader();
                    break;
                case "DATAMATRIX":
                    r  = new com.google.zxing.datamatrix.DataMatrixReader();
                    break;

                //Auto-Detect:
                case "UPC_EAN":
                    r = new com.google.zxing.oned.MultiFormatUPCEANReader(zxingHints);
                    break;
                case "ALL_1D":
                    r = new com.google.zxing.oned.MultiFormatOneDReader(zxingHints);
                    break;

                default:
                    r = null;
                    if (LastCaptureResults != null)
                    {
                        LastCaptureResults.ExceptionThrown = new ArgumentException("Error: Unknown barcode type");
                    }
                    throw new ArgumentException("Error: Unknown barcode type");
            }
            return r;
        }