private void TryAddFloater(ImageViewerItem item)
        {
            PDF417BarcodeData barcodeData = (PDF417BarcodeData)BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.PDF417);

            barcodeData.SetData(_data);
            _engine.Writer.CalculateBarcodeDataBounds(LeadRect.Empty,
                                                      item.Image.XResolution,
                                                      item.Image.YResolution,
                                                      barcodeData,
                                                      _writeOptions);
            if (barcodeData.Rect.Width <= item.Image.Width && barcodeData.Rect.Height <= item.Image.Height)
            {
                _bigEnoughForBarcode    = true;
                this.ImageViewer.Cursor = System.Windows.Forms.Cursors.Default;
                RasterImage floaterImage = RasterImage.Create(barcodeData.Rect.Width,
                                                              barcodeData.Rect.Height,
                                                              32,
                                                              Math.Max(item.Image.XResolution, item.Image.YResolution),
                                                              RasterColor.Create(0, 255, 255, 255));

                _engine.Writer.WriteBarcode(floaterImage, barcodeData, _writeOptions);
                item.Floater        = floaterImage;
                item.FloaterOpacity = 0.5;
            }
            else
            {
                this.ImageViewer.Cursor = System.Windows.Forms.Cursors.No;
                _bigEnoughForBarcode    = false;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            String fileToConvert = @"FILE PATH HERE";

            RasterSupport.SetLicense(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC", System.IO.File.ReadAllText(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC.KEY"));

            using (RasterCodecs codecs = new RasterCodecs())
            {
                using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false))
                {
                    ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime");

                    using (IOcrPage ocrPage = ocrEngine.CreatePage(ocrEngine.RasterCodecsInstance.Load(fileToConvert, 1), OcrImageSharingMode.AutoDispose))
                    {
                        ocrPage.AutoZone(null);
                        ocrPage.Recognize(null);
                        string recognizedCharacters = ocrPage.GetText(-1);

                        BarcodeEngine engine     = new BarcodeEngine();
                        int           resolution = 300;
                        using (RasterImage image = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)))
                        {
                            BarcodeWriter writer = engine.Writer;

                            QRBarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;

                            data.Bounds = new LeadRect(0, 0, image.ImageWidth, image.ImageHeight);
                            QRBarcodeWriteOptions writeOptions = writer.GetDefaultOptions(data.Symbology) as QRBarcodeWriteOptions;
                            writeOptions.XModule             = 30;
                            writeOptions.HorizontalAlignment = BarcodeAlignment.Near;
                            writeOptions.VerticalAlignment   = BarcodeAlignment.Near;
                            data.Value = recognizedCharacters;

                            writer.CalculateBarcodeDataBounds(new LeadRect(0, 0, image.ImageWidth, image.ImageHeight), image.XResolution, image.YResolution, data, writeOptions);
                            Console.WriteLine("{0} by {1} pixels", data.Bounds.Width, data.Bounds.Height);

                            writer.WriteBarcode(image, data, writeOptions);

                            CropCommand cmd = new CropCommand(new LeadRect(0, 0, data.Bounds.Width, data.Bounds.Height));
                            cmd.Run(image);

                            codecs.Save(image, "QR.tif", RasterImageFormat.CcittGroup4, 1);

                            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                            {
                                var process = new Process();
                                process.StartInfo = new ProcessStartInfo("QR.tif")
                                {
                                    UseShellExecute = true
                                };
                                process.Start();
                            }

                            Console.WriteLine();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void _availableSymbologyListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            BarcodeSymbology symbology = (BarcodeSymbology)_availableSymbologyListBox.SelectedItem;
            BarcodeData      oldData   = _dataPropertyGrid.SelectedObject as BarcodeData;
            BarcodeData      newData   = BarcodeData.CreateDefaultBarcodeData(symbology);

            // Get the old data bounds and set it into the new barcode
            if (oldData != null)
            {
                newData.Bounds = oldData.Bounds;
            }
            _dataPropertyGrid.SelectedObject = newData;
            UpdateUIState();
        }