Пример #1
0
        protected override void OnCreate(Bundle bundle)

        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;
            MobileBarcodeScanner.Initialize(Application);
            base.OnCreate(bundle);
            Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
            global::Xamarin.Forms.Forms.Init(this, bundle);


            //lazer BarcodeReader broadcastReceiver
            var lazerrec = new BarCodeReader();

            IntentFilter filter = new IntentFilter();

            filter.AddAction("com.zebra.sdl.action.STARTED");
            filter.AddAction("com.zebra.sdl.action.RELEASED");
            filter.AddAction("com.zebra.sdl.action.SCAN_COMPLETE");
            RegisterReceiver(lazerrec, filter);

            //Intent camera = new Intent(MediaStore.ActionImageCapture);
            //StartActivityForResult(camera, 1);

            LoadApplication(new App());
            Task.Run(async() => {
                await GrantPermissions();
            });
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader object and  Set recognition mode and manual hints
                BarCodeReader reader = new BarCodeReader(dataDir + "datamatrix-barcode.jpg", DecodeType.DataMatrix);
                reader.RecognitionMode = RecognitionMode.ManualHints;
                reader.ManualHints = ManualHint.InvertImage | ManualHint.IncorrectBarcodes;

                // Try to recognize all possible barcodes in the image and Display the codetext
                while (reader.Read())
                {
                    Console.WriteLine("Codetext: " + reader.GetCodeText());
                }
                // Close the reader
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
Пример #3
0
        public static void Run()
        {
            try
            {
                // ExStart:GetAllPossible1DBarcodesfromImage
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader object and Call read method
                BarCodeReader reader = new BarCodeReader(dataDir + "Barcode2.png", DecodeType.AllSupportedTypes);
                reader.Read();

                // Now get all possible barcodes
                BarCodeReader.PossibleBarCode[] barcodes = reader.GetAllPossibleBarCodes();
                foreach (BarCodeReader.PossibleBarCode barcode in barcodes)
                {
                    // Display code text, symbology, detected angle, recognition percentage of the barcode
                    Console.WriteLine("Code Text: " + barcode.Codetext + " Symbology: " + barcode.BarCodeReadType + " Recognition percentage: " + barcode.Angle);

                    // Display x and y coordinates of barcode detected
                    Point[] point = barcode.Region.Points;
                    Console.WriteLine("Top left coordinates: X = " + point[0].X + ", Y = " + point[0].Y);
                    Console.WriteLine("Bottom left coordinates: X = " + point[1].X + ", Y = " + point[1].Y);
                    Console.WriteLine("Bottom right coordinates: X = " + point[2].X + ", Y = " + point[2].Y);
                    Console.WriteLine("Top right coordinates: X = " + point[3].X + ", Y = " + point[3].Y);
                }
                // ExEnd:GetAllPossible1DBarcodesfromImage
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:ImageProcessingBarcodeRecognition
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Create an instance of BarCodeReader and set image and symbology type to recognize
                using (BarCodeReader barCodeReader = new BarCodeReader(dataDir + "code39.png", DecodeType.Code39Standard))
                {
                    // Set grayscale image processing
                    barCodeReader.QualitySettings = QualitySettings.MaxBarCodes;

                    // Try to recognize all possible barcodes in the image and Display the codetext
                    foreach (BarCodeResult result in barCodeReader.ReadBarCodes())
                    {
                        Console.WriteLine("Codetext: " + result.CodeText);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:ImageProcessingBarcodeRecognition
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Create an instance of BarCodeReader and set image and symbology type to recognize
                BarCodeReader barCodeReader = new BarCodeReader(dataDir + "code39.png", DecodeType.Code39Standard);

                // Set grayscale image processing
                barCodeReader.RecognitionMode = RecognitionMode.MaxBarCodes;

                // Try to recognize all possible barcodes in the image and Display the codetext
                while (barCodeReader.Read())
                {                  
                    Console.WriteLine("Codetext: " + barCodeReader.GetCodeText());
                }                
                // Close the reader
                barCodeReader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // Create an instance of BarCodeReader and set image and symbology type to recognize
            BarCodeReader barCodeReader = new BarCodeReader(dataDir + "code39.png", DecodeType.Code39Standard);
            int counter = 0;

            // Read all the barcodes from the images
            while (barCodeReader.Read())
            {
                // Display the symbology type, codetext and Get the barcode region
                Console.WriteLine("BarCode Type: " + barCodeReader.GetCodeType());
                Console.WriteLine("BarCode CodeText: " + barCodeReader.GetCodeText());
                BarCodeRegion region = barCodeReader.GetRegion();

                if (region != null)
                {
                    // Initialize an object of type Image to get the Graphics object
                    Image image = Image.FromFile(dataDir + "code39.png");

                    // Initialize graphics object from the image
                    Graphics graphics = Graphics.FromImage(image);

                    // Draw the barcode edges,  Save the image and Fill the barcode area with some color
                    region.DrawBarCodeEdges(graphics, new Pen(Color.Red, 1f));
                    image.Save(dataDir + string.Format(@"edge_{0}.png", counter++));
                    region.FillBarCodeRegion(graphics, Brushes.Green);
                    image.Save(dataDir + string.Format(@"fill_{0}.png", counter++));
                }
            }
            barCodeReader.Close();
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
         
                // Create array for storing multiple bar codes file names
                string[] files = new string[] { "Barcodefrom.png", "Barcode2.png" };

                // Iiterate through the bar code image files
                for (int i = 0; i < files.Length; ++i)
                {
                    // Create instance of BarCodeReader class and set symbology
                    using (BarCodeReader reader = new BarCodeReader(dataDir + files[i], DecodeType.MacroPdf417))
                    {
                        if (reader.Read())
                        {
                            // Get code text, file id, segment id and segment count
                            Console.WriteLine("File Name: " + files[i] + " Code Text: " + reader.GetCodeText());
                            Console.WriteLine("FileID: " + reader.GetMacroPdf417FileID());
                            Console.WriteLine("SegmentID: " + reader.GetMacroPdf417SegmentID());
                            Console.WriteLine("Segment Count: " + reader.GetMacroPdf417SegmentsCount());
                        }
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:SingleWipedBarsInPattern
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader object and  Set recognition mode
                using (BarCodeReader reader = new BarCodeReader(@"file.tiff", DecodeType.Code128))
                {
                    reader.QualitySettings.AllowOneDWipedBarsRestoration = true;
                    List <string> lCodetexts = new List <string>();
                    foreach (BarCodeResult result in reader.ReadBarCodes())
                    {
                        lCodetexts.Add(result.CodeText);
                        Console.WriteLine(result.CodeText);
                    }
                }
                // ExEnd:SingleWipedBarsInPattern
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
Пример #9
0
        public EntranceBase(EntranceInfo info, ParkBase parent)
        {
            Parent    = parent;
            _entrance = info;
            _status   = EntranceStatus.UnKnown; //初始状态设置为未知

            if (info.TicketReaderCOMPort > 0)
            {
                _TicketReader              = new BarCodeReader(info.TicketReaderCOMPort);
                _TicketReader.BarCodeRead += new BarCodeReadEventHandler(TicketReader_BarCodeRead);
                _TicketReader.Open();
            }
            if (info.TicketPrinterCOMPort > 0)
            {
                _TicketPrinter = new KPM150BarCodePrinter(info.TicketPrinterCOMPort);
                _TicketPrinter.Open();
            }
            //初始化处理消息包的线程
            _PacketHandleThread = new Thread(ReportHandle_Thread);
            _PacketHandleThread.Start();

            Thread t = new Thread(new ThreadStart(HeartBeatCheck_Thread));

            t.IsBackground = true;
            t.Start();
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Create an instance of BarCodeReader and set image and symbology type to recognize
                BarCodeReader barCodeReader = new BarCodeReader(dataDir + "code39.png", DecodeType.Code39Standard);

                // Set grayscale image processing
                barCodeReader.RecognitionMode = RecognitionMode.MaxBarCodes;

                // Try to recognize all possible barcodes in the image
                while (barCodeReader.Read())
                {
                    // Display the codetext
                    Console.WriteLine("Codetext: " + barCodeReader.GetCodeText());
                }
                
                // Close the reader
                barCodeReader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {                
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
                Stopwatch sw = new Stopwatch();

                // Start the stopwatch
                sw.Start();

                // Define the settings to use all of the processor cores, if not then how many to use.
                BarCodeReader.ProcessorSettings.UseAllCores = false;
                BarCodeReader.ProcessorSettings.UseOnlyThisCoresCount = 4;

                // Perform the BarCode recognition task Initialize the BarCodeReader object
                using (BarCodeReader reader = new BarCodeReader(dataDir + "code39.png", DecodeType.Code128))
                {
                    while (reader.Read())
                    {
                        Console.WriteLine(" Code Text: " + reader.GetCodeText() + " Type: " + reader.GetCodeType());
                    }
                }

                // Stop the stopwatch
                sw.Stop();

                // Write the Elapsed time to console
                Console.WriteLine("Elapsed: " + sw.Elapsed);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
Пример #12
0
        public static void Run()
        {
            try
            {
                // ExStart:DetectDotPeenDatamatrix
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader class by passing barcode file name and barcode type as parameters
                using (BarCodeReader reader = new BarCodeReader(dataDir + "datamatrix-stars.png", DecodeType.DataMatrix))
                {
                    //set high performance mode
                    reader.QualitySettings = QualitySettings.HighPerformance;
                    reader.QualitySettings.AllowDatamatrixIndustrialBarcodes = true;
                    foreach (BarCodeResult result in reader.ReadBarCodes())
                    {
                        Console.WriteLine(result.CodeType + ": " + result.CodeText);
                    }
                }
                // ExEnd:DetectDotPeenDatamatrix
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // ExStart:GetBarCodeRegionInformationfromImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // Create an instance of BarCodeReader class and read barcode file
            using (BarCodeReader barCodeReader = new BarCodeReader(dataDir + "Region.png", DecodeType.Code39Standard))
            {
                // Try to recognize all possible barcodes in the image
                foreach (BarCodeResult result in barCodeReader.ReadBarCodes())
                {
                    // Get the region information
                    var region = result.Region;
                    if (region != null)
                    {
                        // Display x and y coordinates of barcode detected
                        Point[] point = region.Points;
                        Console.WriteLine("Top left coordinates: X = " + point[0].X + ", Y = " + point[0].Y);
                        Console.WriteLine("Top right coordinates: X = " + point[1].X + ", Y = " + point[1].Y);
                        Console.WriteLine("Bottom right coordinates: X = " + point[2].X + ", Y = " + point[2].Y);
                        Console.WriteLine("Bottom left coordinates: X = " + point[3].X + ", Y = " + point[3].Y);
                    }
                    Console.WriteLine("Codetext: " + result.CodeText);
                }
            }
            // ExEnd:GetBarCodeRegionInformationfromImage
        }
        public static void Run()
        {
            try
            {
                // ExStart:SwitchBarcodeRecognitionModes
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader object and  Set recognition mode
                using (BarCodeReader reader = new BarCodeReader(dataDir + "datamatrix-barcode.jpg", DecodeType.DataMatrix))
                {
                    reader.QualitySettings = QualitySettings.HighPerformance;
                    reader.QualitySettings.AllowInvertImage       = true;
                    reader.QualitySettings.AllowIncorrectBarcodes = true;

                    // Try to recognize all possible barcodes in the image and Display the codetext
                    foreach (BarCodeResult result in reader.ReadBarCodes())
                    {
                        Console.WriteLine("Codetext: " + result.CodeText);
                    }
                }
                // ExEnd:SwitchBarcodeRecognitionModes
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_CreateAndManage2DBarCodes();

            try
            {
                MemoryStream memoryStream = new MemoryStream();
                // Instantiate barcode object, Set CodeText, Barcode Symbology and Text Encoding
                using (BarCodeBuilder barCodeBuilder = new BarCodeBuilder())
                {
                    BarCodeBuilder builder = new BarCodeBuilder("Слово", EncodeTypes.QR);
                    barCodeBuilder.CodeTextEncoding = Encoding.UTF8;
                    barCodeBuilder.Save(dataDir + "" + memoryStream + "_out.png", BarCodeImageFormat.Png);
                }

                string fileName = dataDir + "" + memoryStream + "_out.png";
                using (BarCodeReader reader = new BarCodeReader(fileName, DecodeType.QR))
                {
                    reader.SetDetectEncoding(false);
                    if (reader.Read())
                        Console.WriteLine(reader.GetCodeText(Encoding.UTF8)); //"Слово"
                }

            }
            catch (Exception)
            {}
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.             
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
                string strFileID = "1";
                string[] strFileslist = Directory.GetFiles(dataDir + strFileID + "_*.png");
                foreach (string strFile in strFileslist)
                {
                    // We got list of all the files, now read barcodes
                    BarCodeReader reader = new BarCodeReader(strFile, DecodeType.MacroPdf417);
                    if (reader.Read() == true)
                    {
                        Console.WriteLine("File: " + strFile + " == FileID: " + reader.GetMacroPdf417FileID() +
                            " == SegmentID: " + reader.GetMacroPdf417SegmentID() + "  == CodeText: " + reader.GetCodeText());
                    }

                    // Close the reader
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
Пример #17
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // Instantiate BarCodeReader object
            BarCodeReader reader = new BarCodeReader(dataDir + "rotatedbarcode.jpg", DecodeType.Code128);

            try
            {
                // read Code128 bar code
                while (reader.Read())
                {
                    // detect bar code orientation
                    System.Console.Write(Environment.NewLine + "Rotaion Angle: " + reader.GetAngle());
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }

            Console.WriteLine(Environment.NewLine + "Barcode recognized from " + dataDir + "rotatedbarcode.jpg");
        }
        public static void Run()
        {
            //ExStart:DetectUnicodeEncoding
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_CreateAndManage2DBarCodes();

            try
            {
                MemoryStream memoryStream = new MemoryStream();

                // Instantiate barcode object, Set CodeText, Barcode Symbology and Text Encoding
                using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.QR, "Слово"))
                {
                    generator.Parameters.Barcode.QR.CodeTextEncoding = Encoding.UTF8;
                    generator.Save(dataDir + "" + memoryStream + "_out.png", BarCodeImageFormat.Png);
                }

                string fileName = dataDir + "" + memoryStream + "_out.png";
                using (BarCodeReader reader = new BarCodeReader(fileName, DecodeType.QR))
                {
                    var detectEnc = reader.DetectEncoding;
                    foreach (BarCodeResult result in reader.ReadBarCodes())
                    {
                        Console.WriteLine(result.CodeText); //"Слово"
                    }
                }
            }
            catch (Exception)
            {}
            //ExEnd:DetectUnicodeEncoding
        }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BarCodePutBarCodeRecognizeFromBodyRequest"/> class.
 /// </summary>
 /// <param name="name">The image name.</param>
 /// <param name="barcodeReader">BarCodeReader object with parameters.</param>
 /// <param name="type">The barcode type.</param>
 /// <param name="folder">The image folder.</param>
 public BarCodePutBarCodeRecognizeFromBodyRequest(string name, BarCodeReader barcodeReader = null, string type = null, string folder = null)
 {
     this.name          = name;
     this.barcodeReader = barcodeReader;
     this.type          = type;
     this.folder        = folder;
 }
Пример #20
0
        public static void Run()
        {
            try
            {
                // ExStart:ReadComplexBarcodes
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageComplexBarcodes();

                using (var reader = new BarCodeReader(dataDir + "swissQRCodetext_out.png", DecodeType.QR))
                {
                    foreach (BarCodeResult barcodeResult in reader.ReadBarCodes())
                    {
                        SwissQRCodetext result = ComplexCodetextReader.TryDecodeSwissQR(barcodeResult.CodeText);
                        Console.WriteLine("Account :" + result.Bill.Account);
                        Console.WriteLine("BillInformation = " + result.Bill.BillInformation);
                        Console.WriteLine("Currency :" + result.Bill.Currency);
                    }
                }
                // ExEnd:ReadComplexBarcodes
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
Пример #21
0
        static void Main(string[] args)
        {
            Product      productHolder;
            ProductShelf productShelf  = new ProductShelf();
            Order        productsOrder = new Order();

            productHolder = new Product(1, "Cachorro Quente", 4);
            productShelf.AddProductToShelf(productHolder);

            productHolder = new Product(2, "X-Salada", 4.5);
            productShelf.AddProductToShelf(productHolder);

            productHolder = new Product(3, "X-Bacon", 5);
            productShelf.AddProductToShelf(productHolder);

            productHolder = new Product(4, "Torrada Simples", 2);
            productShelf.AddProductToShelf(productHolder);

            productHolder = new Product(5, "Refrigerante", 1.5);
            productShelf.AddProductToShelf(productHolder);

            string barCodeRead = InputSystem.ReadLine;

            BarCodeReader codeReader = new BarCodeReader(barCodeRead);

            Product productToAdd = productShelf.ProductInShelfWithID(codeReader.ReadNumberInBarCode(0));
            int     productQty   = codeReader.ReadNumberInBarCode(1);

            productsOrder.AddProductToOrder(productToAdd, productQty);

            productsOrder.ListTotalOrder();
            Console.ReadLine();
        }
Пример #22
0
        public static void Run()
        {
            // ExStart:ReadMultipleMacropdf417BarcodeImages
            try
            {
                // The path to the documents directory.
                string   dataDir      = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
                string   strFileID    = "1";
                string[] strFileslist = Directory.GetFiles(dataDir + strFileID + "_*.png");
                foreach (string strFile in strFileslist)
                {
                    // We got list of all the files, now read barcodes
                    BarCodeReader reader = new BarCodeReader(strFile, DecodeType.MacroPdf417);
                    if (reader.Read() == true)
                    {
                        Console.WriteLine("File: " + strFile + " == FileID: " + reader.GetMacroPdf417FileID() +
                                          " == SegmentID: " + reader.GetMacroPdf417SegmentID() + "  == CodeText: " + reader.GetCodeText());
                    }

                    // Close the reader
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:ReadMultipleMacropdf417BarcodeImages
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader object and Call read method
                BarCodeReader reader = new BarCodeReader(dataDir + "Barcode2.png", DecodeType.AllSupportedTypes);
                reader.Read();

                // Now get all possible barcodes
                BarCodeReader.PossibleBarCode[] barcodes = reader.GetAllPossibleBarCodes();
                foreach (BarCodeReader.PossibleBarCode barcode in barcodes)
                {
                    // Display code text, symbology, detected angle, recognition percentage of the barcode
                    Console.WriteLine("Code Text: " + barcode.Codetext + " Symbology: " + barcode.BarCodeReadType + " Recognition percentage: " + barcode.Angle);

                    // Display x and y coordinates of barcode detected
                    Point[] point = barcode.Region.Points;
                    Console.WriteLine("Top left coordinates: X = " + point[0].X + ", Y = " + point[0].Y);
                    Console.WriteLine("Bottom left coordinates: X = " + point[1].X + ", Y = " + point[1].Y);
                    Console.WriteLine("Bottom right coordinates: X = " + point[2].X + ", Y = " + point[2].Y);
                    Console.WriteLine("Top right coordinates: X = " + point[3].X + ", Y = " + point[3].Y);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
Пример #24
0
        private BarCodeReader BarCodeReaderPdf(String filename)
        {
            //Set license for Aspose.BarCode
            Aspose.BarCode.License licenceBarCode = new Aspose.BarCode.License();
            licenceBarCode.SetLicense(@"X:\awnet\TestData\Licenses\Aspose.Total.lic");

            //bind the pdf document
            Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
            pdfExtractor.BindPdf(filename);

            //set page range for image extraction
            pdfExtractor.StartPage = 1;
            pdfExtractor.EndPage   = 1;

            pdfExtractor.ExtractImage();

            //save image to stream
            MemoryStream imageStream = new MemoryStream();

            pdfExtractor.GetNextImage(imageStream);
            imageStream.Position = 0;

            //recognize the barcode from the image stream above
            BarCodeReader barcodeReader = new BarCodeReader(imageStream, DecodeType.QR);

            while (barcodeReader.Read())
            {
                Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetCodeType());
            }

            //close the reader
            barcodeReader.Close();

            return(barcodeReader);
        }
        public static void Run()
        {
            try
            {
                // ExStart:SwitchBarcodeRecognitionModes
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader object and  Set recognition mode and manual hints
                BarCodeReader reader = new BarCodeReader(dataDir + "datamatrix-barcode.jpg", DecodeType.DataMatrix);
                reader.RecognitionMode = RecognitionMode.ManualHints;
                reader.ManualHints     = ManualHint.InvertImage | ManualHint.IncorrectBarcodes;

                // Try to recognize all possible barcodes in the image and Display the codetext
                while (reader.Read())
                {
                    Console.WriteLine("Codetext: " + reader.GetCodeText());
                }
                // Close the reader
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:SwitchBarcodeRecognitionModes
        }
Пример #26
0
        public static void Run()
        {
            try
            {
                // ExStart:ReadBarcodeFromTIFFImages
                // The path to the documents directory.
                string dataDir    = RunExamples.GetDataDir_ManageBarCodes();
                var    img        = Image.FromFile(dataDir + "tiffImage.tif");
                int    totalFrame = img.GetFrameCount(FrameDimension.Page);

                // Feed the pages to BarCodeReader one by one
                for (int i = 0; i < totalFrame; i++)
                {
                    // Set the active page and feed it to the BarCodeReader
                    var           w      = img.SelectActiveFrame(FrameDimension.Page, i);
                    var           bitmap = new Bitmap(img);
                    BarCodeReader reader = new BarCodeReader(bitmap, DecodeType.AllSupportedTypes);
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetCodeText() + " " + reader.GetCodeType());
                    }
                }
                // ExEnd:ReadBarcodeFromTIFFImages
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Пример #27
0
        // Read a set of barcodes from an image.
        private BarCode[] RecognizeBarcodes(BarCodeReader reader, ReadOpts optionsIn)
        {
            BarCode[] results = null;
            var       options = new ReadOpts(optionsIn);

            if (options.Symbology == 0)
            {
                return(null);
            }

            try
            {
                results = reader.ReadBars(options);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                _statusBox.AppendText("Range error in options: " + ex.Message + "\r\n");
            }
            catch (Exception ex)
            {
                _statusBox.AppendText("General error: " + ex.Message + "\r\n");
            }

            return(results);
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Create an instance of BarCodeReader class and specify an area to look for the barcode
                BarCodeReader reader = new BarCodeReader(new Bitmap(dataDir + "ReadBarcodefromSpecificRegionofImage.png"), new Rectangle(0, 0, 100, 50), DecodeType.Pdf417);

                // Read all barcodes in the provided area
                while (reader.Read() == true)
                {
                    // Display the codetext and symbology type of the barcode found
                    Console.WriteLine("Codetext: " + reader.GetCodeText() + " Symbology: " + reader.GetCodeType());
                }

                // Close the reader
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:ReadBarcodeFromTIFFImages
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageBarCodes();
                var img = Image.FromFile(dataDir + "tiffImage.tif");
                int totalFrame = img.GetFrameCount(FrameDimension.Page);

                // Feed the pages to BarCodeReader one by one
                for (int i = 0; i < totalFrame; i++)
                {
                    // Set the active page and feed it to the BarCodeReader
                    var w = img.SelectActiveFrame(FrameDimension.Page, i);
                    var bitmap = new Bitmap(img);
                    BarCodeReader reader = new BarCodeReader(bitmap, DecodeType.AllSupportedTypes);
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetCodeText() + " " + reader.GetCodeType());
                    }
                }
                // ExEnd:ReadBarcodeFromTIFFImages
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {
                Stopwatch watch = new Stopwatch();

                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                using (BarCodeReader reader = new BarCodeReader(dataDir + "SymbologyTypebarcode.png", DecodeType.Code128))
                {
                    // Start Stopwatch
                    watch.Start();

                    // Set RecognitionMode
                    reader.RecognitionMode = RecognitionMode.ManualHints;

                    // Set ManualHints
                    reader.ManualHints = ManualHint.MedianSmoothing;

                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetCodeType() + ": " + reader.GetCodeText());
                    }
                    // End Stopwatch
                    watch.Stop();
                    Console.WriteLine("Time: " + watch.ElapsedMilliseconds + "ms.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
        }
Пример #31
0
        public static void Run()
        {
            try
            {
                // ExStart:MarkingBarCodeRegionsInImage
                Stopwatch watch = new Stopwatch();
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
                using (BarCodeReader reader = new BarCodeReader(dataDir + "Code128.jpg", DecodeType.Code128))
                {
                    // Start Stopwatch and Set RecognitionMode, ManualHints
                    watch.Start();
                    //reader.RecognitionMode = RecognitionMode.ManualHints;
                    reader.QualitySettings.AllowMedianSmoothing      = true;
                    reader.QualitySettings.MedianSmoothingWindowSize = 5;

                    foreach (BarCodeResult result in reader.ReadBarCodes())
                    {
                        Console.WriteLine(result.CodeType + ": " + result.CodeText);
                    }

                    // End Stopwatch
                    watch.Stop();
                    Console.WriteLine("Time: " + watch.ElapsedMilliseconds + "ms.");
                }
                // ExEnd:MarkingBarCodeRegionsInImage
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_BarCodeRecognition();
            string dst     = dataDir + "Code39.png";

            // Instantiate BarCodeReader object
            BarCodeReader reader = new BarCodeReader(dst, BarCodeReadType.Code39Standard);

            try
            {
                // read Code39 bar code
                while (reader.Read())
                {
                    // detect bar code orientation
                    System.Console.Write(Environment.NewLine + "Rotaion Angle: " + reader.GetAngle());
                }
                reader.Close();
            }

            catch (Exception exp)
            {
                System.Console.Write(exp.Message);
            }

            Console.WriteLine(Environment.NewLine + "Barcode recognized from " + dst);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // Create an instance of BarCodeReader class and read barcode file
            BarCodeReader barCodeReader = new BarCodeReader(dataDir + "Region.png", DecodeType.Code39Standard);

            // Try to recognize all possible barcodes in the image
            while (barCodeReader.Read())
            {
                // Get the region information
                BarCodeRegion region = barCodeReader.GetRegion();
                if (region != null)
                {
                    // Display x and y coordinates of barcode detected
                    Point[] point = region.Points;
                    Console.WriteLine("Top left coordinates: X = " + point[0].X + ", Y = " + point[0].Y);
                    Console.WriteLine("Top right coordinates: X = " + point[1].X + ", Y = " + point[1].Y);
                    Console.WriteLine("Bottom right coordinates: X = " + point[2].X + ", Y = " + point[2].Y);
                    Console.WriteLine("Bottom left coordinates: X = " + point[3].X + ", Y = " + point[3].Y);
                }
                Console.WriteLine("Codetext: " + barCodeReader.GetCodeText());
            }
            // Close reader
            barCodeReader.Close();
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // create an instance of BarCodeReader class and read barcode file
            BarCodeReader barCodeReader = new BarCodeReader(dataDir + "Region.png", DecodeType.Code39Standard);

            // Try to recognize all possible barcodes in the image
            while (barCodeReader.Read())
            {
                // Get the region information
                BarCodeRegion region = barCodeReader.GetRegion();
                if (region != null)
                {
                    // Display x and y coordinates of barcode detected
                    Point[] point = region.Points;
                    Console.WriteLine("Top left coordinates: X = " + point[0].X + ", Y = " + point[0].Y);
                    Console.WriteLine("Top right coordinates: X = " + point[1].X + ", Y = " + point[1].Y);
                    Console.WriteLine("Bottom right coordinates: X = " + point[2].X + ", Y = " + point[2].Y);
                    Console.WriteLine("Bottom left coordinates: X = " + point[3].X + ", Y = " + point[3].Y);
                }
                Console.WriteLine("Codetext: " + barCodeReader.GetCodeText());
            }
            // Close reader
            barCodeReader.Close();
        }
Пример #35
0
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader class by passing barcode file name and barcode type as parameters
                using (BarCodeReader reader = new BarCodeReader(dataDir + "testDotPeen.png", DecodeType.DataMatrix))
                {
                    // Set the reader recognition mode.
                    reader.RecognitionMode = RecognitionMode.ManualHints;

                    // Set Manual Hint property to speed up recognition process.
                    reader.ManualHints = ManualHint.SpecialFormOfCells;
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetCodeType() + ": " + reader.GetCodeText());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
        }
Пример #36
0
        // ExStart:ReadAndSortBarcodesInSpecificOrder
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir             = RunExamples.GetDataDir_ManageBarCodes();
            List <FoundBarCodes> found = new List <FoundBarCodes>();

            using (BarCodeReader reader = new BarCodeReader(dataDir + "tiffImage.tif", DecodeType.Code128))
            {
                while (reader.Read())
                {
                    found.Add(new FoundBarCodes(reader.GetCodeText(), reader.GetRegion()));
                }
            }
            found.Sort(new FoundComparator());
            int i = 1;

            foreach (FoundBarCodes barcode in found)
            {
                Console.WriteLine("Codetext ( " + i + " ): " + barcode.CodeText);
                Console.WriteLine("Top left coordinates: X = " + barcode.region.Points[0].X + ", Y = " + barcode.region.Points[0].Y);
                Console.WriteLine("Bottom left coordinates: X = " + barcode.region.Points[1].X + ", Y = " + barcode.region.Points[1].Y);
                Console.WriteLine("Bottom right coordinates: X = " + barcode.region.Points[2].X + ", Y = " + barcode.region.Points[2].Y);
                Console.WriteLine("Top right coordinates: X = " + barcode.region.Points[3].X + ", Y = " + barcode.region.Points[3].Y);
                Console.WriteLine();
                i++;
            }
        }
Пример #37
0
        public static void Run()
        {
            // ExStart:ScanBarCodePicture
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            try
            {
                // Read file from directory with DecodeType.EAN13
                using (BarCodeReader reader = new BarCodeReader(dataDir + "Scan.jpg", DecodeType.EAN13))
                {
                    foreach (BarCodeResult result in reader.ReadBarCodes())
                    {
                        // Read symbology type and code text
                        Console.WriteLine("Symbology Type: " + result.CodeType);
                        Console.WriteLine("CodeText: " + result.CodeText);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from https://www.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:ScanBarCodePicture
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
                // Create array for storing multiple bar codes file names
                string[] files = new string[] { "Barcodefrom.png", "Barcode2.png" };

                // Iiterate through the bar code image files
                for (int i = 0; i < files.Length; ++i)
                {
                    // Create instance of BarCodeReader class and set symbology
                    using (BarCodeReader reader = new BarCodeReader(dataDir + files[i], DecodeType.MacroPdf417))
                    {
                        if (reader.Read())
                        {
                            // Get code text
                            Console.WriteLine("File Name: " + files[i] + " Code Text: " + reader.GetCodeText());
                            // Get file id
                            Console.WriteLine("FileID: " + reader.GetMacroPdf417FileID());
                            // Get segment id
                            Console.WriteLine("SegmentID: " + reader.GetMacroPdf417SegmentID());
                            // Get segment count
                            Console.WriteLine("Segment Count: " + reader.GetMacroPdf417SegmentsCount());
                        }
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
        }
Пример #39
0
        public static void Run()
        {
            // ExStart:RecognizeBarcodeFromWordDocument
            // For complete examples and data files, please go to https://github.com/aspose-barcode/Aspose.BarCode-for-.NET

            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_TechnicalArticles();

            // Load the word document, get all the shapes
            Document       wordDocument = new Document(dataDir + "Document.doc");
            NodeCollection shapes       = wordDocument.GetChildNodes(NodeType.Shape, true);

            // Loop through all the shapes
            foreach (Shape shape in shapes)
            {
                // Check if it has an image
                if (shape.HasImage)
                {
                    // Save the image in memory stream
                    MemoryStream imgStream = new MemoryStream();
                    shape.ImageData.Save(imgStream);

                    // Recognize the barcode from the image stream above
                    using (BarCodeReader reader = new BarCodeReader(new Bitmap(imgStream), DecodeType.Code39Standard))
                    {
                        foreach (BarCodeResult result in reader.ReadBarCodes())
                        {
                            Console.WriteLine("Codetext found: " + result.CodeType + ", Symbology: " + result.CodeText);
                        }
                    }
                }
                // ExEnd:RecognizeBarcodeFromWordDocument
                Console.WriteLine(Environment.NewLine + "Recognize Barcode From Word Document Finished.");
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_BarCodeRecognition();
            string dst = dataDir + "Code39.png";

            // Instantiate BarCodeReader object
            BarCodeReader reader = new BarCodeReader(dst, BarCodeReadType.Code39Standard);

            try
            {
                // read Code39 bar code
                while (reader.Read())
                {
                    // detect bar code orientation
                    System.Console.Write(Environment.NewLine + "Rotaion Angle: " + reader.GetAngle());
                }
                reader.Close();
            }

            catch (Exception exp)
            {

                System.Console.Write(exp.Message);
            }

            Console.WriteLine(Environment.NewLine + "Barcode recognized from " + dst);
        }
        public static void Run()
        {
            try
            {
                // ExStart:SetBarcodeOrientation
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Create an instance of BarCodeReader and set image and symbology type to recognize
                BarCodeReader barCodeReader = new BarCodeReader(dataDir + "BarcodeOrientation.png", DecodeType.Code39Standard);

                // Aspose.BarCode.BarCodeRecognition.RecognitionHints is obsolete: RecognitionHints is depricated
                // Barcode orientation is detected automatically
                // barCodeReader.OrientationHints = RecognitionHints.Orientation.Rotate90;

                // Try to recognize all possible barcodes in the image and Display the codetext
                while (barCodeReader.Read())
                {
                    Console.WriteLine("Codetext: " + barCodeReader.GetCodeText());
                }

                // Close the reader
                barCodeReader.Close();
                // ExEnd:SetBarcodeOrientation
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {
                Stopwatch watch = new Stopwatch();

                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
                using (BarCodeReader reader = new BarCodeReader(dataDir + "SymbologyTypebarcode.png", DecodeType.Code128))
                {
                    // Start Stopwatch and Set RecognitionMode, ManualHints
                    watch.Start();
                    reader.RecognitionMode = RecognitionMode.ManualHints;
                    reader.ManualHints = ManualHint.MedianSmoothing;
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetCodeType() + ": " + reader.GetCodeText());
                    }

                    // End Stopwatch
                    watch.Stop();
                    Console.WriteLine("Time: " + watch.ElapsedMilliseconds + "ms.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
Пример #43
0
        public static void Run()
        {
            try
            {
                // ExStart:ReadBarcodeSpecificRegionOfImage
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Create an instance of BarCodeReader class and specify an area to look for the barcode
                using (BarCodeReader reader = new BarCodeReader(new Bitmap(dataDir + "ReadBarcodefromSpecificRegionofImage.png"), new Rectangle(0, 0, 100, 50), DecodeType.Pdf417))
                {
                    // Read all barcodes in the provided area
                    foreach (BarCodeResult result in reader.ReadBarCodes())
                    {
                        // Display the codetext and symbology type of the barcode found
                        Console.WriteLine("Codetext: " + result.CodeText + " Symbology: " + result.CodeType);
                    }
                }
                // ExEnd:ReadBarcodeSpecificRegionOfImage
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // Initialize the BarCodeReader object and Set RecognitionMode
            using (BarCodeReader reader = new BarCodeReader(dataDir + "code39.png", DecodeType.Code39Standard))
            {
                reader.RecognitionMode = RecognitionMode.MaxBarCodes;
                while (reader.Read())
                {
                    Console.WriteLine(reader.GetCodeType() + ": " + reader.GetCodeText());
                    Console.WriteLine("IsDeniable: " + reader.GetIsDeniable());
                }
            }
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Create instance of BarCodeBuilder class and Get code text
                BarCodeReader reader = new BarCodeReader(dataDir + "Scan.jpg");
                while (reader.Read())
                {
                    Console.WriteLine("CodeText: " + reader.GetCodeText());
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
          
            // Initialize the Bitmap object            
            Bitmap bitmap = new Bitmap(dataDir + "Region.png");
            Rectangle[] areas = new Rectangle[3];
            areas[0] = new Rectangle(50, 50, 300, 300);
            areas[1] = new Rectangle(400, 40, 350, 350);
            areas[2] = new Rectangle(40, 500, 700, 150);

            // Initialize the BarCodeReader object and load bitmap object       
            using (BarCodeReader reader = new BarCodeReader(bitmap, areas, DecodeType.Code39Standard))
            {
                while (reader.Read())
                {
                    Console.WriteLine(reader.GetCodeType() + ": " + reader.GetCodeText());
                }
            }
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader object and Call read method
                BarCodeReader reader = new BarCodeReader(dataDir + "Barcode2.png", DecodeType.AllSupportedTypes);
                while (reader.Read())
                {
                    Console.WriteLine(reader.GetCodeText() + " Type: " + reader.GetCodeType());
                    float percent = reader.GetRecognitionQuality();
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:GenerateAndRecognizeUTF8Characters
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageBarCodes();

                // Generate the barcode
                Bitmap imgBarcode = null;
                BarCodeBuilder objBarCodeBuilder = new BarCodeBuilder {EncodeType = EncodeTypes.MacroPdf417};
                
                // Set the codetext by converting it into unicode byte array
                byte[] byteArray = Encoding.Unicode.GetBytes("منحة");
                objBarCodeBuilder.SetBinaryCodeText(byteArray);
                imgBarcode = objBarCodeBuilder.GenerateBarCodeImage();
                imgBarcode.Save(dataDir + "GenerateAndRecognizeUTF8Characters_out.png");

                // Recognize the above barcode
                BarCodeReader reader = new BarCodeReader(dataDir + "GenerateAndRecognizeUTF8Characters_out.png");
                while (reader.Read())
                {
                    Encoding unicode = Encoding.Unicode;
                   
                    // Get the characters array from the bytes
                    char[] unicodeChars = new char[unicode.GetCharCount(reader.GetCodeBytes(), 0, reader.GetCodeBytes().Length)];
                    unicode.GetChars(reader.GetCodeBytes(), 0, reader.GetCodeBytes().Length, unicodeChars, 0);
                    
                    // Build unicode string
                    string strCodeText = new string(unicodeChars);
                    Console.WriteLine(strCodeText);
                }
                reader.Close();
                // ExEnd:GenerateAndRecognizeUTF8Characters
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // Instantiate BarCodeReader object
            BarCodeReader reader = new BarCodeReader(dataDir + "rotatedbarcode.jpg", DecodeType.Code128);
            try
            {
                // Read Code128 bar code and Detect bar code orientation
                while (reader.Read())
                {
                    Console.Write(Environment.NewLine + "Rotaion Angle: " + reader.GetAngle());
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
            Console.WriteLine(Environment.NewLine + "Barcode recognized from " + dataDir + "rotatedbarcode.jpg");
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            try
            {
                // Read file from directory with DecodeType.EAN13
                BarCodeReader reader = new BarCodeReader(dataDir + "Scan.jpg", DecodeType.EAN13);
                while (reader.Read())
                {
                    // Read symbology type and code text
                    Console.WriteLine("Symbology Type: " + reader.GetCodeType());
                    Console.WriteLine("CodeText: " + reader.GetCodeText());
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {                 
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();
                BaseDecodeType[] objArray = new BaseDecodeType[] { DecodeType.Code39Standard, DecodeType.Pdf417 };

                // Initialize the BarCodeReader, Call Read() method in a loop and  Display the codetext and symbology type
                BarCodeReader reader = new BarCodeReader(dataDir + "RecognizingMultipleSymbologies.png",objArray);
                while (reader.Read())
                {
                    Console.WriteLine("Codetext: " + reader.GetCodeText());
                    Console.WriteLine("Symbology type: " + reader.GetCodeType());
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:RecognizeBarcodeWithTurkishCharacters
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageBarCodes();

                // Load barcode image and Read barcode
                var reader = new BarCodeReader(dataDir + "Turkish.png", DecodeType.Pdf417);
                while (reader.Read())
                {
                    var t = reader.GetCodeBytes();
                    var encodingValue = Encoding.GetEncoding(1254).GetString(t);
                }
                reader.Close();
                // ExEnd:RecognizeBarcodeWithTurkishCharacters
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {                                         
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

                // Initialize the BarCodeReader class by passing barcode file name and barcode type as parameters            
                using (BarCodeReader reader = new BarCodeReader(dataDir + "datamatrix-stars.png", DecodeType.DataMatrix))
                {
                    // Set the reader recognition mode and  Manual Hint property to speed up recognition process.
                    reader.RecognitionMode = RecognitionMode.ManualHints;
                    reader.ManualHints = ManualHint.SpecialFormOfCells;
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetCodeType() + ": " + reader.GetCodeText());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from http://wwww.aspose.com/purchase/default.aspx.");
            }
        }
        private OperationResult ValidatePageCounts(string pathTofile)
        {
            OperationResult operationResult = new OperationResult();
            bool foundBarCode = false;
            string currentUser = Utility.GetUserName();
            int testCounter = 1;
            string currentPatientID = string.Empty;
            string currentTabID = string.Empty;

            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(pathTofile);
            barCodeText = new List<ScannedDocument>();

            int pageCount = pdfDocument.Pages.Count;

            for (var i = 1; i <= pageCount; i++)
            {
                var converter = new PdfConverter();
                converter.BindPdf(pathTofile);
                converter.StartPage = i;
                converter.EndPage = i;
                converter.RenderingOptions.BarcodeOptimization = true;
                converter.Resolution = new Aspose.Pdf.Devices.Resolution(300);
                converter.DoConvert();
                MemoryStream stream = new MemoryStream();
                converter.GetNextImage(stream, ImageFormat.Png);
                using (BarCodeReader reader = new BarCodeReader(stream, BarCodeReadType.Code39Standard))
                {
                    while (reader.Read())
                    {
                        string[] barCodeDocument = reader.GetCodeText().Split('-');
                        ScannedDocument scannedDocument = new ScannedDocument();
                        scannedDocument.PatientID = barCodeDocument[0];
                        scannedDocument.TabID = barCodeDocument[1];
                        scannedDocument.CurrentPageNumber = int.Parse(barCodeDocument[2]);
                        scannedDocument.PageCount = int.Parse(barCodeDocument[3]);
                        scannedDocument.Text = reader.GetCodeText();
                        scannedDocument.FullPath = pathTofile;
                        scannedDocument.User = currentUser;
                        barCodeText.Add(scannedDocument);
                        foundBarCode = true;
                    }
                }
                converter.Close();
                converter.Dispose();

                if (foundBarCode != true)
                {
                    operationResult.Success = false;
                    operationResult.ErrorMessage = "Job Failed: Could not Read Bar Code";
                    return operationResult;
                }
                foundBarCode = false;
            }

            //Step 1 Check to be sure the number of pages in the document
            //matches the number of pages in the bar code
            int pdfPageCount = 0;
            int pdfPageCountCheck = 0;
            Aspose.Pdf.Document pdfDocumentPageCount = new Aspose.Pdf.Document(barCodeText[0].FullPath);
            pdfPageCount = pdfDocumentPageCount.Pages.Count;

            currentPatientID = barCodeText[0].PatientID;
            currentTabID = barCodeText[0].TabID;

            for (int i = 0; i < barCodeText.Count; i++)
            {
                try
                {
                    if (int.Parse(barCodeText[i].PatientID) < 1)
                    {
                        operationResult.Success = false;
                        operationResult.ErrorMessage = "Patient ID Invalid";
                        return operationResult;
                    }
                }
                catch 
                {
                    operationResult.Success = false;
                    operationResult.ErrorMessage = "Patient ID Invalid";
                    return operationResult;
                }
                try
                {
                    if (int.Parse(barCodeText[i].TabID) < 1)
                    {
                        operationResult.Success = false;
                        operationResult.ErrorMessage = "Tab ID Invalid";
                        return operationResult;
                    }
                }
                catch
                {
                    operationResult.Success = false;
                    operationResult.ErrorMessage = "Tab ID Invalid";
                    return operationResult;
                }

                if (testCounter == barCodeText[i].CurrentPageNumber && barCodeText[i].PageCount == barCodeText[i].CurrentPageNumber && barCodeText[i].PatientID == currentPatientID && barCodeText[i].TabID == currentTabID)
                {
                    //string[] barCodePageCount = barCodeText[i].Text.Split('-');
                    pdfPageCountCheck = pdfPageCountCheck + barCodeText[i].PageCount;
                    testCounter = 1;

                    if (barCodeText[i].PageCount == barCodeText[i].CurrentPageNumber)
                    {

                        try
                        {
                            currentPatientID = barCodeText[i + 1].PatientID;
                            currentTabID = barCodeText[i + 1].TabID;
                        }
                        catch { }
                    }
                }
                else
                {
                    if (testCounter == barCodeText[i].CurrentPageNumber && barCodeText[i].PatientID == currentPatientID && barCodeText[i].TabID == currentTabID)
                    {
                        testCounter++;
                    }
                    else
                    {
                        operationResult.Success = false;
                        operationResult.ErrorMessage = "Job Failed: Documents out of Order";
                        return operationResult;
                    }
                }
            }

            if (pageCount != pdfPageCountCheck)
            {
                operationResult.Success = false;
                operationResult.ErrorMessage = "Job Failed: Documents out of Order";
                return operationResult;
            }

            operationResult.Success = true;
            operationResult.ErrorMessage = "Job Confirmed";
            return operationResult;
        }
Пример #55
0
        private BarCodeReader BarCodeReaderPdf(string filename)
        {
            //Set license for Aspose.BarCode
            Aspose.BarCode.License licenceBarCode = new Aspose.BarCode.License();

            licenceBarCode.SetLicense(@"X:\awnet\TestData\Licenses\Aspose.Total.lic");

            //bind the pdf document
            Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
            pdfExtractor.BindPdf(filename);

            //set page range for image extraction
            pdfExtractor.StartPage = 1;
            pdfExtractor.EndPage = 1;

            pdfExtractor.ExtractImage();

            //save image to stream
            MemoryStream imageStream = new MemoryStream();
            pdfExtractor.GetNextImage(imageStream);
            imageStream.Position = 0;

            //recognize the barcode from the image stream above
            BarCodeReader barcodeReader = new BarCodeReader(imageStream, DecodeType.QR);
            while (barcodeReader.Read())
            {
                Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetCodeType());
            }

            //close the reader
            barcodeReader.Close();

            return barcodeReader;
        }