/// <summary> /// To scan the Image and return the Barcode Data on it /// </summary> /// <returns>String</returns> public string getBarcodeData() { string barcode; WriteableBitmap wbmp = new WriteableBitmap(ImageSource); RGBLuminanceSource lum = new RGBLuminanceSource(wbmp, wbmp.PixelWidth, wbmp.PixelHeight); HybridBinarizer binarizer = new HybridBinarizer(lum); BinaryBitmap binBmp = new BinaryBitmap(binarizer); try { Result res = OneDreader.decode(binBmp); barcode = res.Text; return barcode; } catch { } try { Result res = QRreader.decode(binBmp); barcode = res.Text; return barcode; } catch { } try { Result res = Matreader.decode(binBmp); barcode = res.Text; return barcode; } catch { } try { Result res = pdfReader.decode(binBmp); barcode = res.Text; return barcode; } catch { } return barcode = "No Barcode Found"; //If no matching found }
private Result decodeInternal(BinaryBitmap image) { int size = readers.Count; for (int i = 0; i < size; i++) { Reader reader = readers[i]; try { return reader.decode(image, hints); } catch (ReaderException) { // continue } } throw ReaderException.Instance; }
/// <summary> Decode an image using the state set up by calling setHints() previously. Continuous scan /// clients will get a <b>large</b> speed increase by using this instead of decode(). /// /// </summary> /// <param name="image">The pixel data to decode /// </param> /// <returns> The contents of the image /// </returns> /// <throws> ReaderException Any errors which occurred </throws> public Result decodeWithState(BinaryBitmap image) { // Make sure to set up the default state so we don't crash if (readers == null) { Hints = null; } return decodeInternal(image); }
/// <summary> Decode an image using the hints provided. Does not honor existing state. /// /// </summary> /// <param name="image">The pixel data to decode /// </param> /// <param name="hints">The hints to use, clearing the previous state. /// </param> /// <returns> The contents of the image /// </returns> /// <throws> ReaderException Any errors which occurred </throws> public Result decode(BinaryBitmap image, Dictionary<DecodeHintType, Object> hints) { Hints = hints; return decodeInternal(image); }
/// <summary> This version of decode honors the intent of Reader.decode(BinaryBitmap) in that it /// passes null as a hint to the decoders. However, that makes it inefficient to call repeatedly. /// Use setHints() followed by decodeWithState() for continuous scan applications. /// /// </summary> /// <param name="image">The pixel data to decode /// </param> /// <returns> The contents of the image /// </returns> /// <throws> ReaderException Any errors which occurred </throws> public Result decode(BinaryBitmap image) { Hints = null; return decodeInternal(image); }
/// <summary> /// To scan the Image and return the Barcode format on it. /// </summary> /// <returns>String</returns> public string getBarcodeFormat() { string format; WriteableBitmap wbmp = new WriteableBitmap(ImageSource); RGBLuminanceSource lum = new RGBLuminanceSource(wbmp, wbmp.PixelWidth, wbmp.PixelHeight); HybridBinarizer binarizer = new HybridBinarizer(lum); BinaryBitmap binBmp = new BinaryBitmap(binarizer); try { Result res = OneDreader.decode(binBmp); format = res.BarcodeFormat.ToString(); return format; } catch { } try { Result res = QRreader.decode(binBmp); format = res.BarcodeFormat.ToString(); return format; } catch { } try { Result res = Matreader.decode(binBmp); format = res.BarcodeFormat.ToString(); return format; } catch { } try { Result res = pdfReader.decode(binBmp); format = res.BarcodeFormat.ToString(); return format; } catch { } return format = "No Format"; //If no matching found }