示例#1
0
        //解码
        private void btnDecode_Click(object sender, EventArgs e)
        {
            try
            {
                //创建解码器
                MultiFormatReader reader = new MultiFormatReader();
                Bitmap            bitmap = (Bitmap)Bitmap.FromFile(decodePath);
                if (bitmap == null)
                {
                    return;
                }

                LuminanceSource ls = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
                BinaryBitmap    bb = new BinaryBitmap(new HybridBinarizer(ls));

                //注意编码对应 : UTF-8
                Hashtable hints = new Hashtable();
                hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
                Result result = reader.decode(bb, hints);
                txtMsgDecode.Text = result.Text;
                labShow.Text      = "解码成功!";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private bool Zxing()
        {
            LuminanceSource source = new RGBLuminanceSource(img, img.Width, img.Height);

            com.google.zxing.BinaryBitmap bitmap1 = new com.google.zxing.BinaryBitmap(new HybridBinarizer(source));
            Result result;

            try
            {
                result = new MultiFormatReader().decode(bitmap1);
                Camera.Stop();
                scanTimer.Stop();
                System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    epStatus.Visibility   = Visibility.Visible;
                    imgScan.Visibility    = Visibility.Collapsed;
                    QRCodeInfo qRCodeInfo = new QRCodeInfo(this, result.Text);
                    qRCodeInfo.Show();
                }));
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
        void skenirajSliku()
        {
            try
            {
                Bitmap             img2    = (Bitmap)pbCamera.Image;
                Reader             reader  = new MultiFormatReader();
                RGBLuminanceSource source1 = new RGBLuminanceSource(img2, img2.Width, img2.Height);
                BinaryBitmap       bitmap  = new BinaryBitmap(new HybridBinarizer(source1));

                Result result = reader.decode(bitmap);
                if (!dekodirao)
                {
                    dekodirao = true;
                    btnStop_Click(null, null);
                    MessageBox.Show("Dekodirao sam: " + result.Text);
                }
                else
                {
                    btnStop_Click(null, null);
                }
            }
            catch (Exception e1)
            {
                Console.WriteLine("GRESKA: (vjerovatno je slika lose kvalitete, probaj rotirati) - tj. nisam uspio prepoznati sliku");
            }
        }
示例#4
0
        public Result Decode(string path)
        {
            Bitmap image;

            try
            {
                image = (Bitmap)Image.FromFile(path);
            }
            catch (Exception)
            {
                throw new FileNotFoundException("Resource not found: " + path);
            }

            using (image)
            {
                LuminanceSource source;
                source = new BitmapLuminanceSource(image);
                BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
                Result       result = new MultiFormatReader().decode(bitmap);
                if (result == null)
                {
                    throw new Exception("Unable to decode QR code.");
                }
                return(result);
            }
        }
 public XmlTestFactory(PrecisionModel pm, IGeometryOperation geometryOperation, IResultMatcher resultMatcher)
 {
     ObjGeometryFactory = new GeometryFactory(pm);
     _geometryOperation = geometryOperation;
     _resultMatcher     = resultMatcher;
     _objReader         = new MultiFormatReader(ObjGeometryFactory);
 }
示例#6
0
 private void Scan(object sender, EventArgs e)
 {
     using (System.IO.Stream stream = webRes.GetResponseStream())
     {
         Bitmap            img    = new Bitmap(Image.FromStream(stream));
         MultiFormatReader reader = new MultiFormatReader();
         ZXing.Multi.GenericMultipleBarcodeReader barcodeReader = new ZXing.Multi.GenericMultipleBarcodeReader(reader);
         if (img != null)
         {
             pictureBox1.Image = img;
             LuminanceSource source       = new BitmapLuminanceSource(img);
             BinaryBitmap    binaryBitmap = new BinaryBitmap(new ZXing.Common.HybridBinarizer(source));
             Result[]        results      = barcodeReader.decodeMultiple(binaryBitmap);
             if (results != null)
             {
                 timer.Stop();
                 foreach (Result result in results)
                 {
                     //firstly upload img.
                     //Because that server communication with algorithm after getting projectInfo
                     //sync not async
                     UploadProImg(img);                             //upload project img
                     Thread.Sleep(500);                             //process wait 500, socket sync is stupid
                     string identifyResult = UploadProInfo(result); //prase project info and upload
                     MessageBox.Show(identifyResult);
                 }
             }
         }
     }
 }
示例#7
0
        public static string DecodeFromImage(Texture2D image)
        {
            Debuger.Log(LOG_TAG, "DecodeFromImage() ");

            try
            {
                Color32LuminanceSource src = new Color32LuminanceSource(image.GetPixels32(), image.width, image.height);

                Binarizer    bin = new GlobalHistogramBinarizer(src);
                BinaryBitmap bmp = new BinaryBitmap(bin);

                MultiFormatReader mfr    = new MultiFormatReader();
                Result            result = mfr.decode(bmp);

                if (result != null)
                {
                    return(result.Text);
                }
                else
                {
                    Debuger.LogError(LOG_TAG, "DecodeFromImage() Decode 失败!");
                }
            }
            catch (Exception e)
            {
                Debuger.LogError(LOG_TAG, "DecodeFromImage() " + e.Message);
            }

            return("");
        }
示例#8
0
 public static string DecodeQRcodeImage(Texture2D texture2D)
 {
     try
     {
         Color32LuminanceSource color32LuminanceSource = new Color32LuminanceSource(texture2D.GetPixels32(), texture2D.width, texture2D.height);
         Binarizer         binarizer         = new GlobalHistogramBinarizer(color32LuminanceSource);
         BinaryBitmap      binaryBitmap      = new BinaryBitmap(binarizer);
         MultiFormatReader multiFormatReader = new MultiFormatReader();
         Result            result            = multiFormatReader.decode(binaryBitmap);
         if (result != null)
         {
             return(result.Text);
         }
         else
         {
             Debuger.LogError("Decode QRcode Image Error");
             return(String.Empty);
         }
     }
     catch (Exception e)
     {
         Debuger.LogError("Decode QRcode Image Error " + e.Message);
         return(String.Empty);
     }
 }
示例#9
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (pbSlika.Image == null)
            {
                MessageBox.Show("Niste uslikali ništa!");
                return;
            }
            btnStop_Click(null, null);
            dekodirao = false;
            try
            {
                Bitmap             img2    = (Bitmap)pbCamera.Image;
                Reader             reader  = new MultiFormatReader();
                RGBLuminanceSource source1 = new RGBLuminanceSource(img2, img2.Width, img2.Height);
                BinaryBitmap       bitmap  = new BinaryBitmap(new HybridBinarizer(source1));

                Result result = reader.decode(bitmap);
                if (!dekodirao)
                {
                    dekodirao = true;
                    MessageBox.Show("Dekodirao sam: " + result.Text);
                }
                //BarCodeDetectTimer.Stop();
            }
            catch (Exception e1)
            {
                MessageBox.Show("GRESKA: (vjerovatno je slika lose kvalitete, probaj rotirati) - nisam uspio prepoznati sliku");
            }
        }
示例#10
0
        MultiFormatReader GetReader(BarcodeFormat?format, KeyValuePair <DecodeHintType, object>[] aditionalHints)
        {
            var reader = new MultiFormatReader();

            var hints = new Dictionary <DecodeHintType, object>();

            if (format.HasValue)
            {
                hints.Add(DecodeHintType.POSSIBLE_FORMATS, new List <BarcodeFormat>()
                {
                    format.Value
                });
            }
            if (aditionalHints != null)
            {
                foreach (var ah in aditionalHints)
                {
                    hints.Add(ah.Key, ah.Value);
                }
            }

            reader.Hints = hints;

            return(reader);
        }
示例#11
0
        private bool Zxing()
        {
            LuminanceSource source = new RGBLuminanceSource(img, img.Width, img.Height);

            com.google.zxing.BinaryBitmap bitmap1 = new com.google.zxing.BinaryBitmap(new HybridBinarizer(source));
            Result result;

            try
            {
                result    = new MultiFormatReader().decode(bitmap1);
                isScaning = false;
                scanTimer.Stop();
                System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    btnScan.Content = "Scan";
                    tbQRCode.Text   = result.Text;
                }));

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#12
0
        public Result Decode(BinaryBitmap image, BarcodeFormat format, KeyValuePair <DecodeHintType, object>[] aditionalHints = null)
        {
            MultiFormatReader r      = GetReader(format, aditionalHints);
            Result            result = r.decode(image);

            return(result);
        }
        public MultiFormatReader BuildMultiFormatReader()
        {
            var reader = new MultiFormatReader();

            var hints = new Dictionary <DecodeHintType, object>();

            if (this.TryHarder.HasValue && this.TryHarder.Value)
            {
                hints.Add(DecodeHintType.TRY_HARDER, this.TryHarder.Value);
            }
            if (this.PureBarcode.HasValue && this.PureBarcode.Value)
            {
                hints.Add(DecodeHintType.PURE_BARCODE, this.PureBarcode.Value);
            }
            //if (this.AutoRotate.HasValue && this.AutoRotate.Value)

            if (this.PossibleFormats != null && this.PossibleFormats.Count > 0)
            {
                hints.Add(DecodeHintType.POSSIBLE_FORMATS, this.PossibleFormats);
            }

            reader.Hints = hints;

            return(reader);
        }
示例#14
0
        public MultiFormatReader GetReader(BarcodeFormat format, KeyValuePair <DecodeHintType, object>[] additionalHints)
        {
            var reader = new MultiFormatReader();

            var hints = new System.Collections.Generic.Dictionary <DecodeHintType, object>();



            hints.Add(DecodeHintType.POSSIBLE_FORMATS, new List <BarcodeFormat>()
            {
                format
            });


            if (additionalHints != null)
            {
                foreach (var ah in additionalHints)
                {
                    hints.Add(ah.Key, ah.Value);
                }
            }


            reader.Hints = hints;

            return(reader);
        }
示例#15
0
        private Result decode(Uri uri, IDictionary <DecodeHintType, object> hints)
        {
            Bitmap image;

            try
            {
                image = (Bitmap)Bitmap.FromFile(uri.LocalPath);
            }
            catch (Exception)
            {
                throw new FileNotFoundException("Resource not found: " + uri);
            }

            LuminanceSource source;

            if (config.Crop == null)
            {
                source = new BitmapLuminanceSource(image);
            }
            else
            {
                int[] crop = config.Crop;
                source = new BitmapLuminanceSource(image).crop(crop[0], crop[1], crop[2], crop[3]);
            }
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

            if (config.DumpBlackPoint)
            {
                dumpBlackPoint(uri, image, bitmap);
            }
            Result result = new MultiFormatReader().decode(bitmap, hints);

            if (result != null)
            {
                if (config.Brief)
                {
                    Console.Out.WriteLine(uri + ": Success");
                }
                else
                {
                    ParsedResult parsedResult = ResultParser.parseResult(result);
                    Console.Out.WriteLine(uri + " (format: " + result.BarcodeFormat + ", type: " +
                                          parsedResult.Type + "):\nRaw result:\n" + result.Text + "\nParsed result:\n" +
                                          parsedResult.DisplayResult);

                    Console.Out.WriteLine("Found " + result.ResultPoints.Length + " result points.");
                    for (int i = 0; i < result.ResultPoints.Length; i++)
                    {
                        ResultPoint rp = result.ResultPoints[i];
                        Console.Out.WriteLine("  Point " + i + ": (" + rp.X + ',' + rp.Y + ')');
                    }
                }
            }
            else
            {
                Console.Out.WriteLine(uri + ": No barcode found");
            }
            return(result);
        }
        public XmlTestFactory(PrecisionModel pm, IGeometryOperation geometryOperation, IResultMatcher resultMatcher)
        {
            var gs = new NtsGeometryServices(pm, 0);

            //ObjGeometryFactory = gs.CreateGeometryFactory();
            _geometryOperation = geometryOperation;
            _resultMatcher     = resultMatcher;
            _objReader         = new MultiFormatReader(gs);
        }
示例#17
0
文件: Form1.cs 项目: ssor/csharpDemos
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.pictureBox1.Image == null)
            {
                return;
            }
            Image  img = this.pictureBox1.Image;
            Bitmap bmap;

            try
            {
                bmap = new Bitmap(img);
            }
            catch (System.IO.IOException ioe)
            {
                MessageBox.Show(ioe.ToString());
                return;
            }
            if (bmap == null)
            {
                MessageBox.Show("无法解析该图像!");
                return;
            }

            LuminanceSource source = new BitmapLuminanceSource(bmap);
            BinaryBitmap    bitmap = new BinaryBitmap(new HybridBinarizer(source));
            Result          result;

            try
            {
                result = new MultiFormatReader().decode(bitmap);
            }
            catch (ReaderException re)
            {
                MessageBox.Show("解码出现异常,可能不支持此编码!", "提示");
                //MessageBox.Show(re.ToString());
                return;
            }
            if (result == null)
            {
                //DmtxImageDecoder decoder = new DmtxImageDecoder();
                //var decodedData = decoder.DecodeImage(bmap, 1, new TimeSpan(0, 0, 3));
                //if (decodedData.Count != 1)
                //    throw new Exception("Encoding or decoding failed!");
                Console.WriteLine("解码失败");
            }
            else
            {
                string value = result.Text;
                if (result.BarcodeFormat == BarcodeFormat.PDF_417 || result.BarcodeFormat == BarcodeFormat.AZTEC)
                {
                    value = HttpUtility.UrlDecode(result.Text);
                }
                Console.WriteLine("decode result => format: " + result.BarcodeFormat + "   value: " + value);
            }
        }
示例#18
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (this.pictureBox1.Image == null)
            {
                return;
            }
            Image  img = this.pictureBox1.Image;
            Bitmap bmap;

            try
            {
                bmap = new Bitmap(img);
            }
            catch (System.IO.IOException ioe)
            {
                MessageBox.Show(ioe.ToString());
                return;
            }
            if (bmap == null)
            {
                MessageBox.Show("无法解析该图像!");
                return;
            }
            LuminanceSource source = new RGBLuminanceSource(bmap, bmap.Width, bmap.Height);

            com.google.zxing.BinaryBitmap bitmap = new com.google.zxing.BinaryBitmap(new HybridBinarizer(source));
            Result result;

            try
            {
                result = new MultiFormatReader().decode(bitmap);
            }
            catch (ReaderException re)
            {
                MessageBox.Show("解码出现异常,可能不支持此编码!", "提示");
                //MessageBox.Show(re.ToString());
                return;
            }
            this.textBox1.Text = result.Text;
            if (result.BarcodeFormat == BarcodeFormat.DATAMATRIX)
            {
                this.lblFormat.Text = "Datamatrix";
            }
            else if (result.BarcodeFormat == BarcodeFormat.PDF417)
            {
                this.lblFormat.Text = "PDF417";
            }
            else if (result.BarcodeFormat == BarcodeFormat.QR_CODE)
            {
                this.lblFormat.Text = "QR Code";
            }
            else
            {
                this.lblFormat.Text = "未知格式";
            }
        }
示例#19
0
        private static EncryptedKeyStore BitmapToKeyStore(Bitmap image)
        {
            LuminanceSource source;

            source = new BitmapLuminanceSource(image);
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            Result       result = new MultiFormatReader().decode(bitmap);

            return(result != null?JsonConvert.DeserializeObject <EncryptedKeyStore>(result.Text) : null);
        }
示例#20
0
        private void Initialize()
        {
            // Gets the Dispatcher for the current application so we can invoke the UI-Thread to get
            // preview-image and fire our timer events
            uiDispatcher = Application.Current.RootVisual.Dispatcher;

            InitializeCamera();


            _reader = this.Options.BuildMultiFormatReader();
        }
示例#21
0
 public QrScanner(QrScannerViewController parent)
 {
     this.parent = parent;
     this.reader = new MultiFormatReader {
         Hints = new Hashtable {
             { DecodeHintType.POSSIBLE_FORMATS, new ArrayList {
                   BarcodeFormat.QR_CODE
               } }
         }
     };
 }
示例#22
0
        public ScannerHelper(List <BarcodeFormat> formats, IZxingImageHelper imageHelper)
        {
            this.imageHelper = imageHelper;
            var hints = new Dictionary <DecodeHintType, object>();

            hints.Add(DecodeHintType.POSSIBLE_FORMATS, formats);
            reader = new MultiFormatReader()
            {
                Hints = hints
            };
        }
示例#23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ZXingBarcodeReader"/> class with
        /// a flag indicating if the barcode reader should work accurate and the mode of the binarizer.
        /// </summary>
        /// <param name="accurate">True, when the barcode reader must work accurate.</param>
        /// <param name="binarizerMode">The binarizer mode.</param>
        public ZXingBarcodeReader(bool accurate, BinarizerMode binarizerMode)
        {
            _reader = new MultiFormatReader();

            if (accurate)
            {
                _hints = new Hashtable();
                _hints.Add(DecodeHintType.TRY_HARDER, DecodeHintType.TRY_HARDER);
            }

            _binarizerMode = binarizerMode;
        }
示例#24
0
        public static string Decode(byte[] bytes, int width, int height, BitmapFormat format)
        {
            var          source   = new RGBLuminanceSource(bytes, width, height, format);
            BinaryBitmap bitmap   = new BinaryBitmap(new HybridBinarizer(source));
            Result       qrResult = new MultiFormatReader().decode(bitmap);

            if (qrResult != null)
            {
                return(qrResult.Text);
            }
            return(string.Empty);
        }
示例#25
0
        /// <summary>
        /// 识别二维码
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        private string DistinguishQrImage(Bitmap bm)
        {
            if (bm == null)
            {
                throw new Exception("bitmap is null");
            }
            var source = new RGBLuminanceSource(bm, bm.Width, bm.Height);
            var bbm    = new BinaryBitmap(new HybridBinarizer(source));
            var result = new MultiFormatReader().decode(bbm);

            return(result.Text);
        }
示例#26
0
        private async Task <Result> Decode(IRandomAccessStream stream)
        {
            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

            SoftwareBitmap bitmap = await decoder.GetSoftwareBitmapAsync();

            LuminanceSource   luminanceSource = new SoftwareBitmapLuminanceSource(bitmap);
            Binarizer         binarizer       = new HybridBinarizer(luminanceSource);
            BinaryBitmap      binaryBitmap    = new BinaryBitmap(binarizer);
            MultiFormatReader reader          = new MultiFormatReader();

            return(reader.decode(binaryBitmap));
        }
示例#27
0
        public static string ExtractFromBitmap(Bitmap bitmap)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException(nameof(bitmap));
            }

            var    binaryBitmap      = new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(bitmap)));
            var    multiFormatReader = new MultiFormatReader();
            Result decodedMessage    = multiFormatReader.decode(binaryBitmap);

            return(decodedMessage?.ToString());
        }
        public IActionResult OnPostQRData()
        {
            MemoryStream stream = new MemoryStream();
            string       postFrame;

            Request.Body.CopyTo(stream);
            stream.Position = 0;
            using (StreamReader reader = new StreamReader(stream))
            {
                string requestBody = reader.ReadToEnd();
                if (requestBody.Length > 0)
                {
                    var objFrame = JsonConvert.DeserializeObject <PostdataLesser>(requestBody);
                    if (objFrame != null)
                    {
                        postFrame = objFrame.Frame;

                        var base64Data = Regex.Match(postFrame, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;
                        var binData    = Convert.FromBase64String(base64Data);

                        Bitmap Image;
                        using (var imageStream = new MemoryStream(binData))
                        {
                            Image = new Bitmap(imageStream);
                        }

                        using (Image)
                        {
                            LuminanceSource source;
                            source = new BitmapLuminanceSource(Image);
                            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
                            ZXing.Result result = new MultiFormatReader().decode(bitmap);
                            if (result != null)
                            {
                                var objQR = JsonConvert.DeserializeObject <QRData>(result.Text);// "{ \"f\": \"PF Jedrzej\", \"l\": \"Peziak\", \"un\": \"AndyMaster\", \"id\": 4113648}");

                                ScannedPlayer.KFId = objQR.id;
                                ScannedPlayer.Name = objQR.f + " \"" + objQR.un + "\" " + objQR.l;

                                return(new JsonResult(new
                                {
                                    playerName = ScannedPlayer.Name,
                                    playerID = ScannedPlayer.KFId,
                                }));
                            }
                        }
                    }
                }
            }
            return(Page());
        }
 public ZxingScanner(ZxingViewController parent)
 {
     this.parent = parent;
     this.reader = 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,
                   BarcodeFormat.QR_CODE
               } }
             , { DecodeHintType.TRY_HARDER, true }
         }
     };
 }
示例#30
0
        public Result Decode(FileInfo file, BarcodeFormat format, KeyValuePair <DecodeHintType, object>[] aditionalHints = null)
        {
            MultiFormatReader r = GetReader(format, aditionalHints);

            BinaryBitmap image = GetImage(file);

            if (image is null)
            {
                return(null);
            }
            Result result = r.decode(image);

            return(result);
        }
 public barcodeCreator()
 {
     barcodeReader = new MultiFormatReader();
     barcodeWriter = new MultiFormatWriter();
 }
        private void Initialize()
        {
            //ScanOnAutoFocus = true; // scanOnAutoFocus;

            // Gets the Dispatcher for the current application so we can invoke the UI-Thread to get
            // preview-image and fire our timer events
            uiDispatcher = Application.Current.RootVisual.Dispatcher;

            _reader = this.Options.BuildMultiFormatReader();

            InitializeCamera();            
        }