private void Worker() { if (hints == null) { hints = new Hashtable(); hints.Add(com.google.zxing.DecodeHintType.POSSIBLE_FORMATS, this.Options.GetFormats()); hints.Add(com.google.zxing.DecodeHintType.NEED_RESULT_POINT_CALLBACK, new ResultCallBack(this)); } if (_multiFormatReader == null) { //_multiFormatReader = new com.google.zxing.oned.MultiFormatOneDReader(hints); _multiFormatReader = new com.google.zxing.MultiFormatReader(); _multiFormatReader.Hints = hints; //_multiFormatReader = new MultiFormatReader { // Hints = new Hashtable { // { DecodeHintType.POSSIBLE_FORMATS, new ArrayList { // BarcodeFormat.UPC_A, BarcodeFormat.UPC_E , BarcodeFormat.CODE_128, // BarcodeFormat.CODE_39, BarcodeFormat.EAN_13, BarcodeFormat.EAN_8 // } } // } // }; } using (var ap = new NSAutoreleasePool()) { // Capturing screen image using (var screenImage = CGImage.ScreenImage.WithImageInRect(picFrame)) //.WithImageInRect(picFrame)) { using (var _theScreenImage = UIImage.FromImage(screenImage)) using (var srcbitmap = new Bitmap(_theScreenImage)) { LuminanceSource source = null; BinaryBitmap bitmap = null; try { //Console.WriteLine(screenImage.Width.ToString() + " x " + screenImage.Height.ToString()); //var cropY = (int)((screenImage.Height * 0.4) / 2); source = new RGBLuminanceSource(srcbitmap, screenImage.Width, screenImage.Height); //.crop(0, cropY, 0, screenImage.Height - cropY - cropY); //Console.WriteLine(source.Width + " x " + source.Height); bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { var result = _multiFormatReader.decodeWithState(bitmap); // //var result = _multiFormatReader.decodeWithState (bitmap); //srcbitmap.Dispose(); if (result.Text != null) { //BeepOrVibrate(); _parentViewController.BarCodeScanned(result); } } catch (ReaderException) { } /* * com.google.zxing.common.BitArray row = new com.google.zxing.common.BitArray(screenImage.Width); * * int middle = screenImage.Height >> 1; * int rowStep = System.Math.Max(1, screenImage.Height >> (4)); * * for (int x = 0; x < 9; 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 >= screenImage.Height) * { * // Oops, if we run off the top or bottom, stop * break; * } * * // Estimate black point for this row and load it: * try * { * row = bitmap.getBlackRow(rowNumber, row); * * * var resultb = _multiFormatReader.decodeRow(rowNumber, row, hints); * if(resultb.Text!=null) * { * Console.WriteLine("SCANNED"); * BeepOrVibrate(); * _parentViewController.BarCodeScanned(resultb); * * * break; * } * else { * continue; * } * * } * catch (ReaderException re) * { * continue; * } * * } */ // var result = _barcodeReader.decodeWithState(bitmap); // // if(result.Text!=null) // { // _multiFormatOneDReader = null; // BeepOrVibrate(); // _parentViewController.BarCodeScanned(result); // } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (bitmap != null) { bitmap = null; } if (source != null) { source = null; } // if(srcbitmap!=null) // srcbitmap = null; //if (_theScreenImage != null) // _theScreenImage = null; } } } } GC.Collect(); //Console.WriteLine("Done."); }