public virtual Result decode(BinaryBitmap image, Dictionary <object, object> hints) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image.BlackMatrix); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image.BlackMatrix).detect(hints); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } return(result); }
protected void btnDecode_Click(object sender, EventArgs e) { if (Convert.ToString(Session["isDefaultImage"]) == "IsDefault") { lblErrorDecode.Text = "Upload QR Code First!"; lblErrorDecode.ForeColor = System.Drawing.Color.Red; return; } property.path = Server.MapPath("~/Images/QR_Codes/" + "img.bmp"); System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(File.ReadAllBytes(property.path))); Bitmap bitMap = new Bitmap(image); try { com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitMap, bitMap.Width, bitMap.Height); var binarizer = new com.google.zxing.common.HybridBinarizer(source); var binBitmap = new com.google.zxing.BinaryBitmap(binarizer); QRCodeReader qrCodeReader = new QRCodeReader(); com.google.zxing.Result str = qrCodeReader.decode(binBitmap); txtDecodedOriginalInfo.Text = str.ToString(); lblErrorDecode.Text = "Successfully Decoded!"; lblErrorDecode.ForeColor = System.Drawing.Color.Green; } catch { } }
public Result decode2(BinaryBitmap image, Dictionary<object, object> hints) { int width = image.Width; int height = image.Height; int halfWidth = Math.Floor(width / 2); int halfHeight = Math.Floor(height / 2); BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight); try { return delegate_Renamed.decode2(topLeft, hints); } catch (Exception e) { if (e.Message.IndexOf("ReaderException") < 0) throw e; // continue } BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight); try { return delegate_Renamed.decode2(topRight, hints); } catch (Exception e) { if (e.Message.IndexOf("ReaderException") < 0) throw e; // continue } BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight); try { return delegate_Renamed.decode2(bottomLeft, hints); } catch (Exception e) { if (e.Message.IndexOf("ReaderException") < 0) throw e; // continue } BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight); try { return delegate_Renamed.decode2(bottomRight, hints); } catch (Exception e) { if (e.Message.IndexOf("ReaderException") < 0) throw e; // continue } int quarterWidth = Math.Floor(halfWidth / 2); int quarterHeight = Math.Floor(halfHeight / 2); BinaryBitmap center = image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight); return delegate_Renamed.decode2(center, hints); }
public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image); if (bits.IsBlank()) { return(null); } decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image).detect(); if (detectorResult.IsBlank()) { return(null); } decoderResult = decoder.decode(detectorResult.Bits); if (decoderResult.IsBlank()) { return(null); } points = detectorResult.Points; } return(new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.PDF417)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.Result decode(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.ChecksumException, com.google.zxing.FormatException public Result decode(BinaryBitmap image, IDictionary<DecodeHintType, object> hints) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image.BlackMatrix); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = (new Detector(image.BlackMatrix)).detect(); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.DATA_MATRIX); IList<sbyte[]> byteSegments = decoderResult.ByteSegments; if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } string ecLevel = decoderResult.ECLevel; if (ecLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); } return result; }
/// <summary> /// 解码操作 /// </summary> private void button3_Click(object sender, EventArgs e) { lbshow.Text = ""; if (pictureBox2.Image == null) { lbshow.Text = "未导入图片!"; return; } try { //构建解码器 com.google.zxing.MultiFormatReader mutiReader = new com.google.zxing.MultiFormatReader(); Bitmap img = (Bitmap)pictureBox2.Image; //(Bitmap)Bitmap.FromFile(opFilePath); com.google.zxing.LuminanceSource ls = new RGBLuminanceSource(img, img.Width, img.Height); com.google.zxing.BinaryBitmap bb = new com.google.zxing.BinaryBitmap(new com.google.zxing.common.HybridBinarizer(ls)); //注意 必须是Utf-8编码 Hashtable hints = new Hashtable(); hints.Add(com.google.zxing.EncodeHintType.CHARACTER_SET, "UTF-8"); com.google.zxing.Result r = mutiReader.decode(bb, hints); txtmsg2.Text = r.Text; lbshow.Text = "解码成功!"; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image.BlackMatrix); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image.BlackMatrix).detect(hints); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } return result; }
// public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image.BlackMatrix); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image.BlackMatrix).detect(); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.DATAMATRIX); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } return(result); }
// public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com) { int width = image.Width; int height = image.Height; int halfWidth = width / 2; int halfHeight = height / 2; BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight); try { return(delegate_Renamed.decode(topLeft, hints)); } catch (ReaderException re) { // continue } BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight); try { return(delegate_Renamed.decode(topRight, hints)); } catch (ReaderException re) { // continue } BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight); try { return(delegate_Renamed.decode(bottomLeft, hints)); } catch (ReaderException re) { // continue } BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight); try { return(delegate_Renamed.decode(bottomRight, hints)); } catch (ReaderException re) { // continue } int quarterWidth = halfWidth / 2; int quarterHeight = halfHeight / 2; BinaryBitmap center = image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight); return(delegate_Renamed.decode(center, hints)); }
public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { int width = image.Width; int height = image.Height; int halfWidth = width / 2; int halfHeight = height / 2; BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight); try { return(delegate_Renamed.decode(topLeft, hints)); } catch (ReaderException) { // continue } BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight); try { return(delegate_Renamed.decode(topRight, hints)); } catch (ReaderException) { // continue } BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight); try { return(delegate_Renamed.decode(bottomLeft, hints)); } catch (ReaderException) { // continue } BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight); try { return(delegate_Renamed.decode(bottomRight, hints)); } catch (ReaderException) { // continue } int quarterWidth = halfWidth / 2; int quarterHeight = halfHeight / 2; BinaryBitmap center = image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight); return(delegate_Renamed.decode(center, hints)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.Result[] decodeMultiple(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException public Result[] decodeMultiple(BinaryBitmap image, IDictionary<DecodeHintType, object> hints) { List<Result> results = new List<Result>(); doDecodeMultiple(image, hints, results, 0, 0); if (results.Count == 0) { throw NotFoundException.NotFoundInstance; } return results.ToArray(); }
public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { int width = image.Width; int height = image.Height; int halfWidth = width / 2; int halfHeight = height / 2; BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight); try { return delegate_Renamed.decode(topLeft, hints); } catch (ReaderException re) { // continue } BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight); try { return delegate_Renamed.decode(topRight, hints); } catch (ReaderException re) { // continue } BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight); try { return delegate_Renamed.decode(bottomLeft, hints); } catch (ReaderException re) { // continue } BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight); try { return delegate_Renamed.decode(bottomRight, hints); } catch (ReaderException re) { // continue } int quarterWidth = halfWidth / 2; int quarterHeight = halfHeight / 2; BinaryBitmap center = image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight); return delegate_Renamed.decode(center, hints); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.Result decode(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.ChecksumException, com.google.zxing.FormatException public Result decode(BinaryBitmap image, IDictionary<DecodeHintType, object> hints) { int width = image.Width; int height = image.Height; int halfWidth = width / 2; int halfHeight = height / 2; BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight); try { return @delegate.decode(topLeft, hints); } catch (NotFoundException re) { // continue } BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight); try { return @delegate.decode(topRight, hints); } catch (NotFoundException re) { // continue } BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight); try { return @delegate.decode(bottomLeft, hints); } catch (NotFoundException re) { // continue } BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight); try { return @delegate.decode(bottomRight, hints); } catch (NotFoundException re) { // continue } int quarterWidth = halfWidth / 2; int quarterHeight = halfHeight / 2; BinaryBitmap center = image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight); return @delegate.decode(center, hints); }
public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) { System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); doDecodeMultiple(image, hints, results, 0, 0); if ((results.Count == 0)) { throw ReaderException.Instance; } int numResults = results.Count; Result[] resultArray = new Result[numResults]; for (int i = 0; i < numResults; i++) { resultArray[i] = (Result) results[i]; } return resultArray; }
public Result[] decodeMultiple2(BinaryBitmap image, Dictionary<object, object> hints) { ArrayList results = new ArrayList(); doDecodeMultiple(image, hints, results, 0, 0); if ((results.Count == 0)) { throw new Exception("ReaderException"); } int numResults = results.Count; Result[] resultArray = new Result[numResults]; for (int i = 0; i < numResults; i++) { resultArray[i] = (Result) results[i]; } return resultArray; }
void captureSource_CaptureImageCompleted(object sender, CaptureImageCompletedEventArgs e) { com.google.zxing.qrcode.QRCodeReader qrRead = new com.google.zxing.qrcode.QRCodeReader(); //This is like a platform neutral way of identifying colors in an image RGBLuminanceSource luminiance = new RGBLuminanceSource(e.Result, e.Result.PixelWidth, e.Result.PixelHeight); //The next 2 things are used to change color to black and white to be read by the reader com.google.zxing.common.HybridBinarizer binarizer = new com.google.zxing.common.HybridBinarizer(luminiance); com.google.zxing.BinaryBitmap binBitmap = new com.google.zxing.BinaryBitmap(binarizer); com.google.zxing.Result results = default(com.google.zxing.Result); try { //barcode found results = qrRead.decode(binBitmap); capturedBarcodes.Items.Insert(0, new ScannedImage(results.Text, e.Result)); capturedBarcodes.SelectedIndex = 0; mediaElement1.Stop(); mediaElement1.Play(); ImageBrush brush = new ImageBrush(); brush.ImageSource = e.Result; capturedImage.Fill = brush; } catch (com.google.zxing.ReaderException) { //no barcode found if (captureSource.State == CaptureState.Started) { captureSource.CaptureImageAsync(); } } catch (Exception ex) { MessageBox.Show(ex.Message); StartButton_Click(this, new RoutedEventArgs()); } try { BarcodeRead(this, new CustomEventHandler() { Barcode = results.Text }); } catch (Exception) { //no javascript event attached } }
public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) { System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); doDecodeMultiple(image, hints, results, 0, 0); if ((results.Count == 0)) { throw ReaderException.Instance; } int numResults = results.Count; Result[] resultArray = new Result[numResults]; for (int i = 0; i < numResults; i++) { resultArray[i] = (Result)results[i]; } return(resultArray); }
// added by .net follower (http://dotnetfollower.com) // public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Generic.Dictionary<Object, Object> hints) { // System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com) System.Collections.Generic.List<Object> results = new System.Collections.Generic.List<Object>(10); // added by .net follower (http://dotnetfollower.com) doDecodeMultiple(image, hints, results, 0, 0); if ((results.Count == 0)) { throw ReaderException.Instance; } int numResults = results.Count; Result[] resultArray = new Result[numResults]; for (int i = 0; i < numResults; i++) { resultArray[i] = (Result) results[i]; } return resultArray; }
// Note that we don't try rotation without the try harder flag, even if rotation was supported. public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { var retval = doDecode(image, hints); if (retval.HasValue()) { return(retval); } else { bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER); if (tryHarder && image.RotateSupported) { BinaryBitmap rotatedImage = image.rotateCounterClockwise(); Result result = doDecode(rotatedImage, hints); if (result == null) { return(null); } // Record that we found it rotated 90 degrees CCW / 270 degrees CW System.Collections.Hashtable metadata = result.ResultMetadata; int orientation = 270; if (metadata != null && metadata.ContainsKey(ResultMetadataType.ORIENTATION)) { // But if we found it reversed in doDecode(), add in that result here: orientation = (orientation + ((System.Int32)metadata[ResultMetadataType.ORIENTATION])) % 360; } result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object)orientation); // Update result points ResultPoint[] points = result.ResultPoints; int height = rotatedImage.Height; for (int i = 0; i < points.Length; i++) { points[i] = new ResultPoint(height - points[i].Y - 1, points[i].X); } return(result); } else { return(null); } } }
// public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com) { // System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com) System.Collections.Generic.List <Object> results = new System.Collections.Generic.List <Object>(10); // added by .net follower (http://dotnetfollower.com) doDecodeMultiple(image, hints, results, 0, 0); if ((results.Count == 0)) { throw ReaderException.Instance; } int numResults = results.Count; Result[] resultArray = new Result[numResults]; for (int i = 0; i < numResults; i++) { resultArray[i] = (Result)results[i]; } return(resultArray); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.Result decode(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.FormatException, com.google.zxing.ChecksumException public Result decode(BinaryBitmap image, IDictionary<DecodeHintType, object> hints) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image.BlackMatrix); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = (new Detector(image)).detect(); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } return new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.PDF_417); }
public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image).detect(); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } return new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.PDF417); }
public Result[] decodeMultiple(BinaryBitmap image, Dictionary <object, object> hints) { List <object> results = new List <object>(); doDecodeMultiple(image, hints, results, 0, 0); if ((results.Count == 0)) { throw ReaderException.Instance; } int numResults = results.Count; Result[] resultArray = new Result[numResults]; for (int i = 0; i < numResults; i++) { resultArray[i] = (Result)results[i]; } return(resultArray); }
// public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image).detect(); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } return(new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.PDF417)); }
public Result decode(BinaryBitmap image, Dictionary <object, object> hints) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image).detect(); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } return(new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.PDF417)); }
// Note that we don't try rotation without the try harder flag, even if rotation was supported. //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.Result decode(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.FormatException public virtual Result decode(BinaryBitmap image, IDictionary<DecodeHintType, object> hints) { try { return doDecode(image, hints); } catch (NotFoundException nfe) { bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER); if (tryHarder && image.RotateSupported) { BinaryBitmap rotatedImage = image.rotateCounterClockwise(); Result result = doDecode(rotatedImage, hints); // Record that we found it rotated 90 degrees CCW / 270 degrees CW //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: java.util.Map<com.google.zxing.ResultMetadataType,?> metadata = result.getResultMetadata(); IDictionary<ResultMetadataType, object> metadata = result.ResultMetadata; int orientation = 270; if (metadata != null && metadata.ContainsKey(ResultMetadataType.ORIENTATION)) { // But if we found it reversed in doDecode(), add in that result here: orientation = (orientation + (int) metadata[ResultMetadataType.ORIENTATION]) % 360; } result.putMetadata(ResultMetadataType.ORIENTATION, orientation); // Update result points ResultPoint[] points = result.ResultPoints; if (points != null) { int height = rotatedImage.Height; for (int i = 0; i < points.Length; i++) { points[i] = new ResultPoint(height - points[i].Y - 1, points[i].X); } } return result; } else { throw nfe; } } }
public Result[] decodeMultiple2(BinaryBitmap image, Dictionary<object, object> hints) { ArrayList results = new ArrayList(); DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints); for (int i = 0; i < detectorResult.Length; i++) { try { DecoderResult decoderResult = Decoder.decode2(detectorResult[i].Bits); ResultPoint[] points = detectorResult[i].Points; Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } results.Add(result); } catch (Exception e) { if (e.Message.IndexOf("ReaderException") < 0) throw e; // ignore and continue } } if ((results.Count == 0)) { return EMPTY_RESULT_ARRAY; } else { Result[] resultArray = new Result[results.Count]; for (int i = 0; i < results.Count; i++) { resultArray[i] = (Result) results[i]; } return resultArray; } }
// public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com) { // System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com) System.Collections.Generic.List <Object> results = new System.Collections.Generic.List <Object>(10); // added by .net follower (http://dotnetfollower.com) DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints); for (int i = 0; i < detectorResult.Length; i++) { try { DecoderResult decoderResult = Decoder.decode(detectorResult[i].Bits); ResultPoint[] points = detectorResult[i].Points; Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } results.Add(result); } catch (ReaderException re) { // ignore and continue } } if ((results.Count == 0)) { return(EMPTY_RESULT_ARRAY); } else { Result[] resultArray = new Result[results.Count]; for (int i = 0; i < results.Count; i++) { resultArray[i] = (Result)results[i]; } return(resultArray); } }
public Result[] decodeMultiple(BinaryBitmap image, Dictionary <object, object> hints) { List <object> results = new List <object>(); DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints); for (int i = 0; i < detectorResult.Length; i++) { try { DecoderResult decoderResult = Decoder.decode(detectorResult[i].Bits); ResultPoint[] points = detectorResult[i].Points; Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } results.Add(result); } catch (ReaderException) { // ignore and continue } } if ((results.Count == 0)) { return(EMPTY_RESULT_ARRAY); } else { Result[] resultArray = new Result[results.Count]; for (int i = 0; i < results.Count; i++) { resultArray[i] = (Result)results[i]; } return(resultArray); } }
// added by .net follower (http://dotnetfollower.com) // public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Generic.Dictionary<Object, Object> hints) { // System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com) System.Collections.Generic.List<Object> results = new System.Collections.Generic.List<Object>(10); // added by .net follower (http://dotnetfollower.com) DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints); for (int i = 0; i < detectorResult.Length; i++) { try { DecoderResult decoderResult = Decoder.decode(detectorResult[i].Bits); ResultPoint[] points = detectorResult[i].Points; Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } results.Add(result); } catch (ReaderException re) { // ignore and continue } } if ((results.Count == 0)) { return EMPTY_RESULT_ARRAY; } else { Result[] resultArray = new Result[results.Count]; for (int i = 0; i < results.Count; i++) { resultArray[i] = (Result) results[i]; } return resultArray; } }
// Note that we don't try rotation without the try harder flag, even if rotation was supported. public virtual Result decode2(BinaryBitmap image, Dictionary<object, object> hints) { try { return doDecode(image, hints); } catch (Exception re) { if (re.Message.IndexOf("ReaderException") < 0) throw re; bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER); if (tryHarder && image.RotateSupported) { BinaryBitmap rotatedImage = image.rotateCounterClockwise(); Result result = doDecode(rotatedImage, hints); // Record that we found it rotated 90 degrees CCW / 270 degrees CW Dictionary<object, object> metadata = result.ResultMetadata; int orientation = 270; if (metadata != null && metadata.ContainsKey(ResultMetadataType.ORIENTATION)) { // But if we found it reversed in doDecode(), add in that result here: orientation = (orientation + ((Int32) metadata[ResultMetadataType.ORIENTATION])) % 360; } result.putMetadata(ResultMetadataType.ORIENTATION, (Object) orientation); // Update result points ResultPoint[] points = result.ResultPoints; int height = rotatedImage.Height; for (int i = 0; i < points.Length; i++) { points[i] = new ResultPoint(height - points[i].Y - 1, points[i].X); } return result; } else { throw re; } } }
// Note that we don't try rotation without the try harder flag, even if rotation was supported. // public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public virtual Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com) { try { return(doDecode(image, hints)); } catch (ReaderException re) { bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER); if (tryHarder && image.RotateSupported) { BinaryBitmap rotatedImage = image.rotateCounterClockwise(); Result result = doDecode(rotatedImage, hints); // Record that we found it rotated 90 degrees CCW / 270 degrees CW // System.Collections.Hashtable metadata = result.ResultMetadata; // commented by .net follower (http://dotnetfollower.com) System.Collections.Generic.Dictionary <Object, Object> metadata = result.ResultMetadata; // added by .net follower (http://dotnetfollower.com) int orientation = 270; if (metadata != null && metadata.ContainsKey(ResultMetadataType.ORIENTATION)) { // But if we found it reversed in doDecode(), add in that result here: orientation = (orientation + ((System.Int32)metadata[ResultMetadataType.ORIENTATION])) % 360; } result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object)orientation); // Update result points ResultPoint[] points = result.ResultPoints; int height = rotatedImage.Height; for (int i = 0; i < points.Length; i++) { points[i] = new ResultPoint(height - points[i].Y - 1, points[i].X); } return(result); } else { throw re; } } }
// added by .net follower (http://dotnetfollower.com) // Note that we don't try rotation without the try harder flag, even if rotation was supported. // public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public virtual Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary<Object, Object> hints) { try { return doDecode(image, hints); } catch (ReaderException re) { bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER); if (tryHarder && image.RotateSupported) { BinaryBitmap rotatedImage = image.rotateCounterClockwise(); Result result = doDecode(rotatedImage, hints); // Record that we found it rotated 90 degrees CCW / 270 degrees CW // System.Collections.Hashtable metadata = result.ResultMetadata; // commented by .net follower (http://dotnetfollower.com) System.Collections.Generic.Dictionary<Object, Object> metadata = result.ResultMetadata; // added by .net follower (http://dotnetfollower.com) int orientation = 270; if (metadata != null && metadata.ContainsKey(ResultMetadataType.ORIENTATION)) { // But if we found it reversed in doDecode(), add in that result here: orientation = (orientation + ((System.Int32) metadata[ResultMetadataType.ORIENTATION])) % 360; } result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object) orientation); // Update result points ResultPoint[] points = result.ResultPoints; int height = rotatedImage.Height; for (int i = 0; i < points.Length; i++) { points[i] = new ResultPoint(height - points[i].Y - 1, points[i].X); } return result; } else { throw re; } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.Result[] decodeMultiple(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException public Result[] decodeMultiple(BinaryBitmap image, IDictionary<DecodeHintType, object> hints) { List<Result> results = new List<Result>(); DetectorResult[] detectorResults = (new MultiDetector(image.BlackMatrix)).detectMulti(hints); foreach (DetectorResult detectorResult in detectorResults) { try { DecoderResult decoderResult = Decoder.decode(detectorResult.Bits, hints); ResultPoint[] points = detectorResult.Points; Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); IList<sbyte[]> byteSegments = decoderResult.ByteSegments; if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } string ecLevel = decoderResult.ECLevel; if (ecLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); } results.Add(result); } catch (ReaderException re) { // ignore and continue } } if (results.Count == 0) { return EMPTY_RESULT_ARRAY; } else { return results.ToArray(); } }
public override Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { return maybeReturnResult(ean13Reader.decode(image, hints)); }
public override Result decode(BinaryBitmap image) { return maybeReturnResult(ean13Reader.decode(image)); }
private void doDecodeMultiple(BinaryBitmap image, IDictionary<DecodeHintType, object> hints, IList<Result> results, int xOffset, int yOffset) { Result result; try { result = @delegate.decode(image, hints); } catch (ReaderException re) { return; } bool alreadyFound = false; foreach (Result existingResult in results) { if (existingResult.Text.Equals(result.Text)) { alreadyFound = true; break; } } if (!alreadyFound) { results.Add(translateResultPoints(result, xOffset, yOffset)); } ResultPoint[] resultPoints = result.ResultPoints; if (resultPoints == null || resultPoints.Length == 0) { return; } int width = image.Width; int height = image.Height; float minX = width; float minY = height; float maxX = 0.0f; float maxY = 0.0f; foreach (ResultPoint point in resultPoints) { float x = point.X; float y = point.Y; if (x < minX) { minX = x; } if (y < minY) { minY = y; } if (x > maxX) { maxX = x; } if (y > maxY) { maxY = y; } } // Decode left of barcode if (minX > MIN_DIMENSION_TO_RECUR) { doDecodeMultiple(image.crop(0, 0, (int) minX, height), hints, results, xOffset, yOffset); } // Decode above barcode if (minY > MIN_DIMENSION_TO_RECUR) { doDecodeMultiple(image.crop(0, 0, width, (int) minY), hints, results, xOffset, yOffset); } // Decode right of barcode if (maxX < width - MIN_DIMENSION_TO_RECUR) { doDecodeMultiple(image.crop((int) maxX, 0, width - (int) maxX, height), hints, results, xOffset + (int) maxX, yOffset); } // Decode below barcode if (maxY < height - MIN_DIMENSION_TO_RECUR) { doDecodeMultiple(image.crop(0, (int) maxY, width, height - (int) maxY), hints, results, xOffset, yOffset + (int) maxY); } }
public Result[] decodeMultiple(BinaryBitmap image) { return decodeMultiple(image, null); }
/// <summary> We're going to examine rows from the middle outward, searching alternately above and below the /// middle, and farther out each time. rowStep is the number of rows between each successive /// attempt above and below the middle. So we'd scan row middle, then middle - rowStep, then /// middle + rowStep, then middle - (2 * rowStep), etc. /// rowStep is bigger as the image is taller, but is always at least 1. We've somewhat arbitrarily /// decided that moving up and down by about 1/16 of the image is pretty good; we try more of the /// image if "trying harder". /// /// </summary> /// <param name="image">The image to decode /// </param> /// <param name="hints">Any hints that were requested /// </param> /// <returns> The contents of the decoded barcode /// </returns> /// <throws> ReaderException Any spontaneous errors which occur </throws> private Result doDecode(BinaryBitmap image, Dictionary <object, object> hints) { int width = image.Width; int height = image.Height; BitArray row = new BitArray(width); int middle = height >> 1; bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER); int rowStep = System.Math.Max(1, height >> (tryHarder?7:4)); int maxLines; if (tryHarder) { maxLines = height; // Look at the whole image, not just the center } else { maxLines = 9; // Nine rows spaced 1/16 apart is roughly the middle half of the image } for (int x = 0; x < maxLines; x++) { // Scanning from the middle out. Determine which row we're looking at next: int rowStepsAboveOrBelow = (x + 1) >> 1; bool isAbove = (x & 0x01) == 0; // i.e. is x even? int rowNumber = middle + rowStep * (isAbove?rowStepsAboveOrBelow:-rowStepsAboveOrBelow); if (rowNumber < 0 || rowNumber >= height) { // Oops, if we run off the top or bottom, stop break; } // Estimate black point for this row and load it: try { row = image.getBlackRow(rowNumber, row); } catch (ReaderException) { continue; } // While we have the image data in a BitArray, it's fairly cheap to reverse it in place to // handle decoding upside down barcodes. for (int attempt = 0; attempt < 2; attempt++) { if (attempt == 1) { // trying again? row.reverse(); // reverse the row and continue // This means we will only ever draw result points *once* in the life of this method // since we want to avoid drawing the wrong points after flipping the row, and, // don't want to clutter with noise from every single row scan -- just the scans // that start on the center line. if (hints != null && hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) { Dictionary <object, object> newHints = new Dictionary <object, object>(); System.Collections.IEnumerator hintEnum = hints.Keys.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'" while (hintEnum.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'" System.Object key = hintEnum.Current; if (!key.Equals(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) { newHints[key] = hints[key]; } } hints = newHints; } } try { // Look for a barcode Result result = decodeRow(rowNumber, row, hints); // We found our barcode if (attempt == 1) { // But it was upside down, so note that result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object) 180); // And remember to flip the result points horizontally. ResultPoint[] points = result.ResultPoints; points[0] = new ResultPoint(width - points[0].X - 1, points[0].Y); points[1] = new ResultPoint(width - points[1].X - 1, points[1].Y); } return(result); } catch (ReaderException) { // continue -- just couldn't decode this row } } } throw ReaderException.Instance; }
/// <summary> This method detects a barcode in a "pure" image -- that is, pure monochrome image /// which contains only an unrotated, unskewed, image of a barcode, with some white border /// around it. This is a specialized method that works exceptionally fast in this special /// case. /// </summary> private static BitMatrix extractPureBits(BinaryBitmap image) { // Now need to determine module size in pixels BitMatrix matrix = image.BlackMatrix; int height = matrix.Height; int width = matrix.Width; int minDimension = System.Math.Min(height, width); // First, skip white border by tracking diagonally from the top left down and to the right: int borderWidth = 0; while (borderWidth < minDimension && !matrix.get_Renamed(borderWidth, borderWidth)) { borderWidth++; } if (borderWidth == minDimension) { throw ReaderException.Instance; } // And then keep tracking across the top-left black module to determine module size int moduleEnd = borderWidth; while (moduleEnd < minDimension && matrix.get_Renamed(moduleEnd, moduleEnd)) { moduleEnd++; } if (moduleEnd == minDimension) { throw ReaderException.Instance; } int moduleSize = moduleEnd - borderWidth; // And now find where the rightmost black module on the first row ends int rowEndOfSymbol = width - 1; while (rowEndOfSymbol >= 0 && !matrix.get_Renamed(rowEndOfSymbol, borderWidth)) { rowEndOfSymbol--; } if (rowEndOfSymbol < 0) { throw ReaderException.Instance; } rowEndOfSymbol++; // Make sure width of barcode is a multiple of module size if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) { throw ReaderException.Instance; } int dimension = (rowEndOfSymbol - borderWidth) / moduleSize; // Push in the "border" by half the module width so that we start // sampling in the middle of the module. Just in case the image is a // little off, this will help recover. borderWidth += (moduleSize >> 1); int sampleDimension = borderWidth + (dimension - 1) * moduleSize; if (sampleDimension >= width || sampleDimension >= height) { throw ReaderException.Instance; } // Now just read off the bits BitMatrix bits = new BitMatrix(dimension); for (int y = 0; y < dimension; y++) { int iOffset = borderWidth + y * moduleSize; for (int x = 0; x < dimension; x++) { if (matrix.get_Renamed(borderWidth + x * moduleSize, iOffset)) { bits.set_Renamed(x, y); } } } return bits; }
public override Result decode(BinaryBitmap image, Dictionary <object, object> hints) { return(maybeReturnResult(ean13Reader.decode(image, hints))); }
// added by .net follower (http://dotnetfollower.com) // public override Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public override Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary<Object, Object> hints) { return maybeReturnResult(ean13Reader.decode(image, hints)); }
// public override Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com) public override Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com) { return(maybeReturnResult(ean13Reader.decode(image, hints))); }
public Detector(BinaryBitmap image) { this.image = image; }
public Result decode(BinaryBitmap image) { return decode(image, null); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.Result decode(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.FormatException public override Result decode(BinaryBitmap image, IDictionary<DecodeHintType, object> hints) { return maybeReturnResult(ean13Reader.decode(image, hints)); }
/// <summary> Locates and decodes a Data Matrix code in an image. /// /// </summary> /// <returns> a String representing the content encoded by the Data Matrix code /// </returns> /// <throws> ReaderException if a Data Matrix code cannot be found, or cannot be decoded </throws> public Result decode(BinaryBitmap image) { return(decode(image, null)); }
public override Result decode(BinaryBitmap image) { return(maybeReturnResult(ean13Reader.decode(image))); }
/// <summary> We're going to examine rows from the middle outward, searching alternately above and below the /// middle, and farther out each time. rowStep is the number of rows between each successive /// attempt above and below the middle. So we'd scan row middle, then middle - rowStep, then /// middle + rowStep, then middle - (2 * rowStep), etc. /// rowStep is bigger as the image is taller, but is always at least 1. We've somewhat arbitrarily /// decided that moving up and down by about 1/16 of the image is pretty good; we try more of the /// image if "trying harder". /// /// </summary> /// <param name="image">The image to decode /// </param> /// <param name="hints">Any hints that were requested /// </param> /// <returns> The contents of the decoded barcode /// </returns> /// <throws> ReaderException Any spontaneous errors which occur </throws> private Result doDecode(BinaryBitmap image, System.Collections.Hashtable hints) { int width = image.Width; int height = image.Height; BitArray row = new BitArray(width); int middle = height >> 1; bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER); int rowStep = System.Math.Max(1, height >> (tryHarder?7:4)); int maxLines; if (tryHarder) { maxLines = height; // Look at the whole image, not just the center } else { maxLines = 9; // Nine rows spaced 1/16 apart is roughly the middle half of the image } for (int x = 0; x < maxLines; x++) { // Scanning from the middle out. Determine which row we're looking at next: int rowStepsAboveOrBelow = (x + 1) >> 1; bool isAbove = (x & 0x01) == 0; // i.e. is x even? int rowNumber = middle + rowStep * (isAbove?rowStepsAboveOrBelow:- rowStepsAboveOrBelow); if (rowNumber < 0 || rowNumber >= height) { // Oops, if we run off the top or bottom, stop break; } // Estimate black point for this row and load it: try { row = image.getBlackRow(rowNumber, row); } catch (ReaderException) { continue; } // While we have the image data in a BitArray, it's fairly cheap to reverse it in place to // handle decoding upside down barcodes. for (int attempt = 0; attempt < 2; attempt++) { if (attempt == 1) { // trying again? row.reverse(); // reverse the row and continue // This means we will only ever draw result points *once* in the life of this method // since we want to avoid drawing the wrong points after flipping the row, and, // don't want to clutter with noise from every single row scan -- just the scans // that start on the center line. if (hints != null && hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) { System.Collections.Hashtable newHints = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); // Can't use clone() in J2ME System.Collections.IEnumerator hintEnum = hints.Keys.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'" while (hintEnum.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'" System.Object key = hintEnum.Current; if (!key.Equals(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) { newHints[key] = hints[key]; } } hints = newHints; } } try { // Look for a barcode Result result = decodeRow(rowNumber, row, hints); // We found our barcode if (attempt == 1) { // But it was upside down, so note that result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object) 180); // And remember to flip the result points horizontally. ResultPoint[] points = result.ResultPoints; points[0] = new ResultPoint(width - points[0].X - 1, points[0].Y); points[1] = new ResultPoint(width - points[1].X - 1, points[1].Y); } return result; } catch (ReaderException) { // continue -- just couldn't decode this row } } } throw ReaderException.Instance; }
// added by .net follower (http://dotnetfollower.com) // private void doDecodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints, System.Collections.ArrayList results, int xOffset, int yOffset) // commented by .net follower (http://dotnetfollower.com) private void doDecodeMultiple(BinaryBitmap image, System.Collections.Generic.Dictionary<Object, Object> hints, System.Collections.Generic.List<Object> results, int xOffset, int yOffset) { Result result; try { result = delegate_Renamed.decode(image, hints); } catch (ReaderException re) { return ; } bool alreadyFound = false; for (int i = 0; i < results.Count; i++) { Result existingResult = (Result) results[i]; if (existingResult.Text.Equals(result.Text)) { alreadyFound = true; break; } } if (alreadyFound) { return ; } results.Add(translateResultPoints(result, xOffset, yOffset)); ResultPoint[] resultPoints = result.ResultPoints; if (resultPoints == null || resultPoints.Length == 0) { return ; } int width = image.Width; int height = image.Height; float minX = width; float minY = height; float maxX = 0.0f; float maxY = 0.0f; for (int i = 0; i < resultPoints.Length; i++) { ResultPoint point = resultPoints[i]; float x = point.X; float y = point.Y; if (x < minX) { minX = x; } if (y < minY) { minY = y; } if (x > maxX) { maxX = x; } if (y > maxY) { maxY = y; } } // Decode left of barcode if (minX > MIN_DIMENSION_TO_RECUR) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" doDecodeMultiple(image.crop(0, 0, (int) minX, height), hints, results, xOffset, yOffset); } // Decode above barcode if (minY > MIN_DIMENSION_TO_RECUR) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" doDecodeMultiple(image.crop(0, 0, width, (int) minY), hints, results, xOffset, yOffset); } // Decode right of barcode if (maxX < width - MIN_DIMENSION_TO_RECUR) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" doDecodeMultiple(image.crop((int) maxX, 0, width - (int) maxX, height), hints, results, xOffset + (int) maxX, yOffset); } // Decode below barcode if (maxY < height - MIN_DIMENSION_TO_RECUR) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" doDecodeMultiple(image.crop(0, (int) maxY, width, height - (int) maxY), hints, results, xOffset, yOffset + (int) maxY); } }
public Result[] decodeMultiple(BinaryBitmap image) { return(decodeMultiple(image, null)); }
public override Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { return(maybeReturnResult(ean13Reader.decode(image, hints))); }
private void doDecodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints, System.Collections.ArrayList results, int xOffset, int yOffset) { Result result; try { result = delegate_Renamed.decode(image, hints); } catch (ReaderException) { return; } bool alreadyFound = false; for (int i = 0; i < results.Count; i++) { Result existingResult = (Result)results[i]; if (existingResult.Text.Equals(result.Text)) { alreadyFound = true; break; } } if (alreadyFound) { return; } results.Add(translateResultPoints(result, xOffset, yOffset)); ResultPoint[] resultPoints = result.ResultPoints; if (resultPoints == null || resultPoints.Length == 0) { return; } int width = image.Width; int height = image.Height; float minX = width; float minY = height; float maxX = 0.0f; float maxY = 0.0f; for (int i = 0; i < resultPoints.Length; i++) { ResultPoint point = resultPoints[i]; float x = point.X; float y = point.Y; if (x < minX) { minX = x; } if (y < minY) { minY = y; } if (x > maxX) { maxX = x; } if (y > maxY) { maxY = y; } } // Decode left of barcode if (minX > MIN_DIMENSION_TO_RECUR) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" doDecodeMultiple(image.crop(0, 0, (int)minX, height), hints, results, xOffset, yOffset); } // Decode above barcode if (minY > MIN_DIMENSION_TO_RECUR) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" doDecodeMultiple(image.crop(0, 0, width, (int)minY), hints, results, xOffset, yOffset); } // Decode right of barcode if (maxX < width - MIN_DIMENSION_TO_RECUR) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" doDecodeMultiple(image.crop((int)maxX, 0, width - (int)maxX, height), hints, results, xOffset + (int)maxX, yOffset); } // Decode below barcode if (maxY < height - MIN_DIMENSION_TO_RECUR) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" doDecodeMultiple(image.crop(0, (int)maxY, width, height - (int)maxY), hints, results, xOffset, yOffset + (int)maxY); } }
/// <summary> Locates and decodes a QR code in an image. /// /// </summary> /// <returns> a String representing the content encoded by the QR code /// </returns> /// <throws> ReaderException if a QR code cannot be found, or cannot be decoded </throws> public virtual Result decode1(BinaryBitmap image) { return decode2(image, null); }
/// <summary> This method detects a barcode in a "pure" image -- that is, pure monochrome image /// which contains only an unrotated, unskewed, image of a barcode, with some white border /// around it. This is a specialized method that works exceptionally fast in this special /// case. /// </summary> private static BitMatrix extractPureBits(BinaryBitmap image) { // Now need to determine module size in pixels BitMatrix matrix = image.BlackMatrix; int height = matrix.Height; int width = matrix.Width; int minDimension = System.Math.Min(height, width); // First, skip white border by tracking diagonally from the top left down and to the right: int borderWidth = 0; while (borderWidth < minDimension && !matrix.get_Renamed(borderWidth, borderWidth)) { borderWidth++; } if (borderWidth == minDimension) { throw ReaderException.Instance; } // And then keep tracking across the top-left black module to determine module size int moduleEnd = borderWidth; while (moduleEnd < minDimension && matrix.get_Renamed(moduleEnd, moduleEnd)) { moduleEnd++; } if (moduleEnd == minDimension) { throw ReaderException.Instance; } int moduleSize = moduleEnd - borderWidth; // And now find where the rightmost black module on the first row ends int rowEndOfSymbol = width - 1; while (rowEndOfSymbol >= 0 && !matrix.get_Renamed(rowEndOfSymbol, borderWidth)) { rowEndOfSymbol--; } if (rowEndOfSymbol < 0) { throw ReaderException.Instance; } rowEndOfSymbol++; // Make sure width of barcode is a multiple of module size if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) { throw ReaderException.Instance; } int dimension = (rowEndOfSymbol - borderWidth) / moduleSize; // Push in the "border" by half the module width so that we start // sampling in the middle of the module. Just in case the image is a // little off, this will help recover. borderWidth += (moduleSize >> 1); int sampleDimension = borderWidth + (dimension - 1) * moduleSize; if (sampleDimension >= width || sampleDimension >= height) { throw ReaderException.Instance; } // Now just read off the bits BitMatrix bits = new BitMatrix(dimension); for (int y = 0; y < dimension; y++) { int iOffset = borderWidth + y * moduleSize; for (int x = 0; x < dimension; x++) { if (matrix.get_Renamed(borderWidth + x * moduleSize, iOffset)) { bits.set_Renamed(x, y); } } } return(bits); }
public override Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) { return(maybeReturnResult(ean13Reader.decode(image, hints))); }