Exemple #1
0
        private void GetThumbnailIfItExists(ImageXTag tag)
        {
            //At Thumbnail Level 1, Tag #513 - JPEGInterchangeFormat
            if (tag.TagLevel == 1 && tag.TagNumber == 513)
            {
                long thumbnailOffset = tag.GetTagUInt32()[0];

                LoadOptions lo = new LoadOptions();
                lo.ImageOffset = (int)thumbnailOffset;

                try
                {
                    if (imageXView1.Image != null)
                    {
                        imageXView1.Image.Dispose();
                        imageXView1.Image = null;
                    }
                    imageXView1.Image = ImageX.FromFile(imagXpress1, filename, lo);

                    ThumbnailLabel.Visible = true;
                    imageXView1.Visible    = true;
                }
                catch (ImageXException ex)
                {
                    MessageBox.Show(ex.Message, Constants.exifThumbnailErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #2
0
 public string Stamp()
 {
     var fileNameOrStream = ...                                                // Get your image from somewhere
                            using (var lifetime = AccusoftProvider.ImagXpress) // Replace this with your own license
     {
         var load = new LoadOptions();
         // All my images are multipage tiff files
         var save = new SaveOptions {
             Format = ImageXFormat.Tiff
         };
         save.Tiff.MultiPage = true;
         using (ImageX image = ImageX.FromFile(lifetime, fileNameOrStream, load))
         {
             int offset = 0;
             int pages  = ImageX.NumPages(lifetime, fileNameOrStream);
             for (int i = 0; i < pages; i++)
             {
                 image.Page            = i + 1;
                 save.Tiff.Compression = image.ImageXData.Compression;
                 var pageStamp = ".."         // Get your stamp
                                 StampImage(lifetime, pageStamp, image);
                 save.Tiff.UseIFDOffset = offset > 0;
                 save.Tiff.IFDOffset    = offset;
                 image.Save(outputFileName, save);
                 offset = save.Tiff.IFDOffset;
             }
         }
     }
 }
Exemple #3
0
        private void mnuOpen_Click(object sender, System.EventArgs e)
        {
            System.String strTmp = AccusoftOpenFile();
            if (strTmp.Length != 0)
            {
                try
                {
                    strImageFile = strTmp;

                    if (imageXView1.Image != null)
                    {
                        imageXView1.Image.Dispose();
                    }

                    imageXView1.Image = ImageX.FromFile(imagXpress1, strImageFile, loLoadOptions);

                    // clear out the error in case there was an error from a previous operation
                    lblerror.Text = "";
                }
                catch (ImagXpressException ex)
                {
                    AccusoftError(ex, lblerror);
                }
                catch (System.IO.IOException ex)
                {
                    AccusoftError(ex, lblerror);
                }
                resultsList.Items.Clear();
            }
        }
Exemple #4
0
 private static void DisposeOfProcessorImage(ImageX procImage)
 {
     if (procImage != null)
     {
         procImage.Dispose();
         procImage = null;
     }
 }
Exemple #5
0
 protected void UpdateOutputImage(ImageX outputImage)
 {
     if (imageXView2.Image != null)
     {
         imageXView2.Image.Dispose();
         imageXView2.Image = null;
     }
     imageXView2.Image = outputImage;
 }
Exemple #6
0
        protected override bool PerformProcessingAction()
        {
            Processor proc = null;

            try
            {
                Point currentScrollPosition;
                if (imageXView2.Image == null)
                {
                    currentScrollPosition = imageXView1.ScrollPosition;
                }
                else
                {
                    currentScrollPosition = imageXView2.ScrollPosition;
                }

                proc         = new Processor(imagXpress1, imageXView1.Image.Copy());
                outputBitmap = proc.GetAlphaChannelAsBitmap();

                imageXView2.ScrollPosition = currentScrollPosition;

                using (ImageX img = ImageX.FromBitmap(imagXpress1, outputBitmap))
                {
                    UpdateOutputImage(img.Copy());
                }

                return(true);
            }
            catch (ProcessorException ex)
            {
                MessageBox.Show(ex.Message, Constants.processingErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (ImageXException ex)
            {
                MessageBox.Show(ex.Message, Constants.processingErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            finally
            {
                if (proc != null)
                {
                    if (proc.Image != null)
                    {
                        proc.Image.Dispose();
                        proc.Image = null;
                    }
                    proc.Dispose();
                    proc = null;
                }
            }
        }
Exemple #7
0
        private void queryFromStreamButton_Click(object sender, EventArgs e)
        {
            try
            {
                System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                AppendFileInfo(ImageX.QueryFromStream(imagXpress1, stream, 1));
                stream.Close();
            }
            catch (Accusoft.ImagXpressSdk.ImagXpressException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #8
0
        private void twainDevice_Scanned(object sender, ScannedEventArgs e)
        {
            IntPtr hdib = e.ScannedImage.ToHdib();

            //must set last parameter to true so Hdib will be cleaned up
            using (ImageX scannedImage = ImageX.FromHdib(imagXpress1, hdib, true))
            {
                imagesScanned.Add(scannedImage.Copy());
            }

            imagesScannedCount = imagesScanned.Count;
            imagesScannedIndex++;

            UpdatePageUI();
        }
Exemple #9
0
        private void queryBufferButton_Click(object sender, EventArgs e)
        {
            try
            {
                System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                Byte[] imgData = new byte[stream.Length];
                stream.Read(imgData, 0, imgData.Length);
                stream.Close();
                AppendFileInfo(ImageX.QueryBuffer(imagXpress1, imgData, 1));
            }
            catch (Accusoft.ImagXpressSdk.ImagXpressException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #10
0
        private void AutoRemoveRedEye_Load(object sender, System.EventArgs e)
        {
            //***The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey methods must be called to distribute the runtime***
            //imagXpress1.Licensing.SetSolutionName("YourSolutionName");
            //imagXpress1.Licensing.SetSolutionKey(12345,12345,12345,12345);
            //imagXpress1.Licensing.SetOEMLicenseKey("1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation�");

            cmbGlare.SelectedIndex = 0;
            cmbShade.SelectedIndex = 0;

            // Because in this sample the ImageX object is always located in the ImageXView
            // tell the ImageXView component to dispose of the ImageX object when itself is
            // disposed. Otherwise, we would have to dispose of the ImageX object in the Form's
            // Dispose method before the components.Dispose() section.
            imageXView1.AutoImageDispose = true;

            try
            {
                //Create a new load options object so we can recieve events from the images we load
                loLoadOptions = new LoadOptions();
            }
            catch (ImagXpressException ex)
            {
                AccusoftError(ex, lblerror);
            }

            try
            {
                imagX1 = new ImageX(imagXpress1);

                //here we set the current directory and image so that the file open dialog box works well
                String strCurrentDir = System.IO.Path.Combine(Application.StartupPath, @"..\..\..\..\..\..\..\..\..\..\Common\Images\");
                if (System.IO.Directory.Exists(strCurrentDir))
                {
                    System.IO.Directory.SetCurrentDirectory(strCurrentDir);
                }
                strCurrentDir = System.IO.Directory.GetCurrentDirectory();

                strImageFile = System.IO.Path.Combine(strCurrentDir, "ImagXpress Redeye 2 Sample.jpg");

                imageXView1.Image = ImageX.FromFile(imagXpress1, strImageFile, loLoadOptions);
            }
            catch (ImagXpressException ex)
            {
                AccusoftError(ex, lblerror);
            }
        }
Exemple #11
0
        public void ConvertTIFtoMultiPage(FileInfo mCaminhoOrigem, FileInfo mCaminhoDestino, string mTipo)
        {
            try
            {
                using (ImagXpress _imageX10 = new ImagXpress())
                {
                    _imageX10.Licensing.UnlockRuntime(1908225079, 373669040, 1341647942, 30454);
                    ImageX image = ImageX.FromFile(_imageX10, mCaminhoOrigem.FullName);
                    try
                    {
                        SaveOptions so = new SaveOptions();
                        so.Format = ImageXFormat.Tiff;
                        if (mTipo.ToUpper() == "PDF")
                        {
                            so.Format = ImageXFormat.Pdf;
                        }

                        so.Tiff.MultiPage = true;
                        so.Pdf.MultiPage  = true;
                        if (image.BitsPerPixel != 1)
                        {
                            so.Tiff.Compression = Compression.Jpeg;
                            so.Pdf.Compression  = Compression.Jpeg;
                        }
                        else
                        {
                            so.Tiff.Compression = Compression.Group4;
                            so.Pdf.Compression  = Compression.Group4;
                        }

                        image.Save(mCaminhoDestino.FullName, so);
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        image.Dispose();
                    }
                }
            }
            catch (Exception exp)
            {
                throw new Exception("Erro ao processar imagem:\t" + exp.Message + Environment.NewLine + exp.StackTrace);
            }
        }
Exemple #12
0
        private Boolean LoadImage(String ImageName)
        {
            if (!File.Exists(ImageName))
            {
                MessageBox.Show("Image Doesn't exist : " + ImageName);
                return(false);
            }

            //Zonal 2
            try
            {
                currentLayer.Elements.Clear();

                InputImg.Image = ImageX.FromFile(imagXpress1, ImageName);
                Processor prc = new PegasusImaging.WinForms.ImagXpress9.Processor(imagXpress1, InputImg.Image);
                if (InputImg.Image.ImageXData.BitsPerPixel != 1)
                {
                    prc.ColorDepth(1, PaletteType.Optimized, DitherType.NoDither);
                    //InputImg.Image = prc.Image;
                }

                //    prc.Rotate(270);
                prc.DocumentDeskew(0, 10, Color.White, true, 99);
                prc.DocumentDespeckle(10, 10);
                InputImg.Image = prc.Image.Copy();

                //InputImg.Image = this.PreprocessImage(this.InputImg.Image);

                frmFilledImage = FormImage.FromHdib(InputImg.Image.ToHdib(false), true, formFix1);

                OutputImg.Image = ImageX.FromHdib(imagXpress1, frmFilledImage.ToHdib(false), true);   //InputImg.Image.Copy();

                OnPictureChanged(ICRType.Image);
                //MessageBox.Show("Load Image");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
Exemple #13
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            //***The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey methods must be called to distribute the runtime***
            //imagXpress1.Licensing.SetSolutionName("YourSolutionName");
            //imagXpress1.Licensing.SetSolutionKey(12345,12345,12345,12345);
            //imagXpress1.Licensing.SetOEMLicenseKey("1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation�");

            // Because in this sample the ImageX object is always located in the ImageXView
            // tell the ImageXView component to dispose of the ImageX object when itself is
            // disposed. Otherwise, we would have to dispose of the ImageX object in the Form's
            // Dispose method before the components.Dispose() section.
            imageXView1.AutoImageDispose = true;

            // Set the current directory to the Common\Images directory
            String strCurrentDir = System.IO.Path.Combine(Application.StartupPath, @"..\..\..\..\..\..\..\..\..\..\Common\Images\");

            if (System.IO.Directory.Exists(strCurrentDir))
            {
                System.IO.Directory.SetCurrentDirectory(strCurrentDir);
            }
            strCurrentDir = System.IO.Directory.GetCurrentDirectory();

            // Initialize the Print Preview Dialog
            InitializePrintPreviewDialog();

            try
            {
                String filename = "vermont.jpg";
                if (System.IO.File.Exists(filename))
                {
                    imageXView1.Image = ImageX.FromFile(imagXpress1, filename);
                }
            }
            catch (Accusoft.ImagXpressSdk.ImagXpressException ex)
            {
                ErrorLabel.Text = ex.Message;
            }
            finally
            {
                EnablePrintButtons(imageXView1.Image != null);
            }
        }
Exemple #14
0
        private void DisplayImage()
        {
            try
            {
                //check if we've reached the end of the images to show
                if (imageFileNameIndex >= imageFileNames.Length)
                {
                    slideShowTimer.Stop();
                    this.DialogResult = DialogResult.OK;
                }

                if (slideShowTimer.Enabled)
                {
                    LoadOptions lo = new LoadOptions();
                    if (imageIsCameraRaw[imageFileNameIndex])
                    {
                        lo.CameraRawEnabled = true;
                    }

                    if (imageXView1.Image != null)
                    {
                        imageXView1.Image.Dispose();
                        imageXView1.Image = null;
                    }
                    imageXView1.Image = ImageX.FromFile(imagXpress1, imageFileNames[imageFileNameIndex], imagePageNumbers[imageFileNameIndex], lo);

                    ImageLabel.Text = String.Format("{0}, Page: {1}, Image {2} of {3}", imageFileNames[imageFileNameIndex],
                                                    imagePageNumbers[imageFileNameIndex], imageFileNameIndex + 1, imageFileNames.Length);
                    //center label
                    ImageLabel.Left    = this.Width / 2 - ImageLabel.Width / 2;
                    ImageLabel.Visible = true;

                    imageFileNameIndex++;
                    slideShowTimer.Interval = 3000;
                }
            }
            catch (ImageXException)
            {
                //error loading image, don't interrupt slide show
                imageFileNameIndex++;
            }
        }
Exemple #15
0
        private Boolean LoadTemplate(String TemplateImageName)
        {
            String TemplateName = TemplateImageName.Substring(TemplateImageName.LastIndexOf("\\") + 1).ToUpper().Replace(".TIF", "");

            if (!File.Exists(TemplateImageName))
            {
                MessageBox.Show("This Template Doecn't Exist!! : " + TemplateImageName);
            }

            // Zonal
            try
            {
                InputImg.Image = ImageX.FromFile(imagXpress1, this.TemplateFile);

                /*
                 * Processor prc = new PegasusImaging.WinForms.ImagXpress9.Processor(imagXpress1, InputImg.Image);
                 * prc.Rotate(270);
                 * InputImg.Image = prc.Image.Copy();
                 */

                InputImg.Image = PreprocessImage(InputImg.Image);


                frmTemplateImage = FormImage.FromHdib(InputImg.Image.ToHdib(false), true, formFix1);

                OutputImg.Image = ImageX.FromHdib(imagXpress1, frmTemplateImage.ToHdib(false), true);   //InputImg.Image.Copy();
                OnPictureChanged(ICRType.Template);

                // MessageBox.Show("Load Template");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                IsTemplateLoaded = false;
                return(false);
            }

            IsTemplateLoaded = true;
            return(true);
        }
Exemple #16
0
        private bool RegisterImage()
        {
            //Zonal 2
            try
            {
                regProcessor = new RegistrationProcessor(formFix1);

                regResult = regProcessor.RegisterToImage(frmFilledImage, frmTemplateImage);

                if (regResult.State == RegistrationState.Failure)
                {
                    MessageBox.Show(regResult.State.ToString());
                }

                frmAlignedImage = regResult.AlignImage(frmFilledImage);

                /*
                 * ImageX FieldImage = new ImageX(imagXpress1);
                 * DropOutProcessor oDrop = new DropOutProcessor(formFix1);
                 * oDrop.DropOutMethod = DropOutMethod.DropOut;
                 * //oDrop.Area = new Rectangle(0, 0, Field.Width, Field.Height);
                 * DropOutResult oDropOutResult = oDrop.CreateImageOfField(frmFilledImage, regResult);
                 */

                //InputImg.Image = ImageX.FromHdib(imagXpress1, oDropOutResult.Image.ToHdib(true), true); //ImageX.FromHdib(imagXpress1, frmAlignedImage.ToHdib(false), true);
                InputImg.Image = ImageX.FromHdib(imagXpress1, frmAlignedImage.ToHdib(false), true);
                // oDrop.Dispose();

                OutputImg.Image = InputImg.Image.Copy();
                OnPictureChanged(ICRType.ImageMatched);

                //  MessageBox.Show("Aligned Image");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(true);
        }
Exemple #17
0
 private void StampImage(ImagXpress lifetime, string text, ImageX destination)
 {
     using (var processor = new Processor(lifetime, destination))
     {
         int bitsPerPixel = destination.ImageXData.BitsPerPixel;
         if (bitsPerPixel != 24)     // we can only paint on a 24 bit image.
         {
             processor.ColorDepth(24, PaletteType.Optimized, DitherType.NoDither);
         }
         using (var g = destination.GetGraphics())
             using (var font = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold))
                 using (var matrix = new Matrix())
                 {
                     try
                     {
                         SizeF textSize = g.MeasureString(text, font);
                         Point location = GetStampLocation(new Size(destination.ImageXData.Width, destination.ImageXData.Height), textSize);
                         // All my stamping is vertically along the left edge
                         matrix.Translate(1, 1);
                         matrix.RotateAt(-90, new PointF(location.X, location.Y));
                         g.Transform = matrix;
                         g.DrawString(text,
                                      font,
                                      Brushes.Black,
                                      location.X, location.Y,
                                      new StringFormat());
                     }
                     finally
                     {
                         destination.ReleaseGraphics();
                     }
                 }
         // The BPP may change accoding to Accusofts documentation, so change it back to what is was
         if (bitsPerPixel != destination.ImageXData.BitsPerPixel)
         {
             processor.ColorDepth(bitsPerPixel, PaletteType.Optimized, DitherType.NoDither);
         }
     }
 }
Exemple #18
0
        private void refreshSideBySideComparison(ListViewItem item)
        {
            Cursor lastCursor = Cursor.Current;

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                inputImageXView.SuspendLayout();
                outputImageXView.SuspendLayout();

                inputFileNameLabel.Text = String.Format("{0}, {1}",
                                                        new object[] { item.SubItems[COLUMN_FILENAME].Text, item.SubItems[COLUMN_FILESIZE].Text });
                inputImageXView.Image = null;
                if (File.Exists(item.SubItems[COLUMN_FILENAME].Text))
                {
                    inputImageXView.Image = ImageX.FromFile(imagXpress1, item.SubItems[COLUMN_FILENAME].Text);
                }

                outputFileNameLabel.Text = String.Format("{0}, {1}",
                                                         new object[] { item.SubItems[COLUMN_FILENAME].Tag, item.SubItems[COLUMN_REDUCEDSIZE].Text });
                outputImageXView.Image = null;
                if (File.Exists((String)item.SubItems[COLUMN_FILENAME].Tag))
                {
                    outputImageXView.Image = ImageX.FromFile(imagXpress1, (String)item.SubItems[COLUMN_FILENAME].Tag);
                }
            }
            catch (ImageXException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                inputImageXView.ResumeLayout();
                outputImageXView.ResumeLayout();
                Cursor.Current = lastCursor;
            }
        }
Exemple #19
0
        protected override bool PerformProcessingAction()
        {
            Processor proc        = null;
            ImageX    sourceImage = null;

            try
            {
                if (String.IsNullOrEmpty(SourceImageTextBox.Text))
                {
                    Helper.ShowBalloonToolTipWarning(
                        SourceImageTextBox.Width - Constants.balloonToolTipHorizontalSpacer,
                        -Constants.balloonToolTipVerticalSpacer, Constants.tooltipInitialDelay,
                        Constants.tooltipDuration, Constants.mergeString, Constants.mergeErrorString,
                        SourceImageTextBox);

                    this.DialogResult = DialogResult.None;

                    return(false);
                }
                else
                {
                    proc = new Processor(imagXpress1, imageXView1.Image.Copy());
                    Helper.TransformIfGrayscale(proc.Image);

                    Point currentScrollPosition;
                    if (imageXView2.Image == null)
                    {
                        currentScrollPosition = imageXView1.ScrollPosition;
                    }
                    else
                    {
                        currentScrollPosition = imageXView2.ScrollPosition;
                    }

                    sourceImage = ImageX.FromFile(imagXpress1, SourceImageTextBox.Text);

                    proc.Merge(ref sourceImage, (MergeSize)MergeSizeComboBox.SelectedIndex,
                               (MergeStyle)MergeStyleComboBox.SelectedIndex, TransparentCheckBox.Checked,
                               TransparentColorButton.BackColor, (int)MergePercentHighNumericUpDown.Value,
                               (int)MergePercentLowNumericUpDown.Value);

                    UpdateOutputImage(proc.Image.Copy());

                    imageXView2.ScrollPosition = currentScrollPosition;

                    return(true);
                }
            }
            catch (ProcessorException ex)
            {
                MessageBox.Show(ex.Message, Constants.processingErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (ImageXException ex)
            {
                MessageBox.Show(ex.Message, Constants.processingErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            finally
            {
                if (sourceImage != null)
                {
                    sourceImage.Dispose();
                    sourceImage = null;
                }
                if (proc != null)
                {
                    if (proc.Image != null)
                    {
                        proc.Image.Dispose();
                        proc.Image = null;
                    }
                    proc.Dispose();
                    proc = null;
                }
            }
        }
Exemple #20
0
 public void SetInputImage(ImageX inputImage)
 {
     imageXView1.Image = inputImage;
 }
Exemple #21
0
        private ImageX PreprocessField(ImageX Image)
        {
            scanFix1.FromHdib(Image.ToHdib(false));

            //Remove Lines

            /*          LineRemovalOptions LineOpts = new LineRemovalOptions();
             *        LineOpts.MinimumLength = 10;
             *        scanFix1.RemoveLines(LineOpts);
             */
            //Despeckle

            DespeckleOptions DespeckOpts = new DespeckleOptions();

            DespeckOpts.SpeckWidth  = 10;
            DespeckOpts.SpeckHeight = 10;
            scanFix1.Despeckle(DespeckOpts);

            //Deskew
            //scanFix1.Deskew();

            //Dilate



            //Comb options

            /*
             * comb = new PegasusImaging.WinForms.ScanFix5.CombRemovalOptions();
             *
             * comb.Area = new System.Drawing.Rectangle(AreaXBar.Value, AreaYBar.Value, AreaWBar.Value, AreaHBar.Value);
             * comb.CombHeight = CombHBar.Value;
             * comb.CombSpacing = SpaceBar.Value;
             * comb.HorizontalLineThickness = HBar.Value;
             * comb.VerticalLineThickness = VBar.Value;
             * comb.MinimumCombLength = LengthBar.Value;
             * comb.MinimumConfidence = ConfidenceBar.Value;
             *
             * scanFix1.RemoveCombs(comb);
             */

            //Smooth Options
            scanFix1.SmoothObjects(10);


            DilateOptions dilate = new DilateOptions();

            dilate.Amount    = 1;
            dilate.Direction = EnhancementDirections.All;

            scanFix1.Dilate(dilate);

            //Blob Options

            /*
             * blob = new PegasusImaging.WinForms.ScanFix5.BlobRemovalOptions();
             *
             * blob.Area = new System.Drawing.Rectangle(BlobAreaXBar.Value, BlobAreaYBar.Value, AreaWidthBar.Value, AreaHeightBar.Value);
             * blob.MaximumPixelCount = MaxCountBar.Value;
             * blob.MinimumPixelCount = MinCountBar.Value;
             * blob.MinimumDensity = DensityBar.Value;
             *
             * scanFix1.RemoveBlobs(blob);
             */

            //Remove Dot Shading

            /*
             * dot = new PegasusImaging.WinForms.ScanFix5.DotShadingRemovalOptions();
             *
             * dot.DensityAdjustment = DotDensityBar.Value;
             * dot.MaximumDotSize = DotSizeBar.Value;
             * dot.HorizontalSizeAdjustment = HAdjBar.Value;
             * dot.VerticalSizeAdjustment = VAdjBar.Value;
             * dot.MinimumAreaHeight = DotHBar.Value;
             * dot.MinimumAreaWidth = DotWBar.Value;
             *
             * scanFix1.RemoveDotShading(dot);
             */


            //Remove Border Options

            /*
             * border = new PegasusImaging.WinForms.ScanFix5.BorderRemovalOptions();
             *
             * border.BorderSpeckSize = BSpeckBar.Value;
             * border.CropBorder = chkcrop.Checked;
             * border.DeskewBorder = chkdeskew.Checked;
             * border.MaximumPageHeight = MaxHeightBar.Value;
             * border.MaximumPageWidth = MaxWidthBar.Value;
             * border.MinimumConfidence = MinConBar.Value;
             * border.MinimumPageHeight = MinHeightBar.Value;
             * border.MinimumPageWidth = SpeckWidthBar.Value;
             * border.PageSpeckSize = PSpeckBar.Value;
             * border.Quality = SpeckQualityBar.Value;
             * border.ReplaceBorder = chkreplace.Checked;
             *
             * if (true)
             * {
             *  border.PadColor = System.Drawing.Color.FromArgb(0, 0, 0);
             * }
             * else
             * {
             *  border.PadColor = System.Drawing.Color.FromArgb(255, 255, 255);
             * }
             * scanFix1.RemoveBorder(border);
             */

            Image = ImageX.FromHdib(imagXpress1, scanFix1.ToHdib(false));



            return(Image);
        }
Exemple #22
0
        public void ProcessFields()
        {
            foreach (ICRField Field in this.Fields)
            {
                ImageX           FieldImage = new ImageX(imagXpress1);
                DropOutProcessor oDrop      = new DropOutProcessor(formFix1);
                oDrop.DropOutMethod         = DropOutMethod.DropOut;
                oDrop.PerformReconstruction = false;
                oDrop.Area = new Rectangle(Field.Left, Field.Top, Field.Width, Field.Height);
                DropOutResult oDropOutResult = oDrop.CreateImageOfField(frmFilledImage, regResult);

                FieldImage = ImageX.FromHdib(imagXpress1, oDropOutResult.Image.ToHdib(true), true);
                oDrop.Dispose();


                OutputFieldImg.Image = FieldImage.Copy();
                OnPictureChanged(ICRType.Field);
                // MessageBox.Show("Field Loaded");
                Application.DoEvents();

                // Set area and analyze field DIB
                SmartZone2.Reader.CharacterSet = Field.CharSet;
                SmartZone2.Reader.Segmentation.SplitMergedChars      = true;
                SmartZone2.Reader.Segmentation.SplitOverlappingChars = true;

                FieldImage = this.PreprocessField(FieldImage);

                OutputFieldImg.Image = FieldImage.Copy();
                OnPictureChanged(ICRType.FieldProcessed);
                //MessageBox.Show("Field Processed");
                Application.DoEvents();

                Rectangle currentArea = new Rectangle(0, 0, Field.Width, Field.Height);
                SmartZone2.Reader.Area = currentArea;
                myTextBlockRes         = SmartZone2.Reader.AnalyzeField(FieldImage.ToHdib(true));


                if (myTextBlockRes.NumberTextLines > 0)
                {
                    //  MessageBox.Show(myTextBlockRes.TextLine(0).Text);

                    Chars.Clear();
                    for (int i = 1; myTextBlockRes.NumberTextLines + 1 != i; i++)
                    {
                        LineResult = myTextBlockRes.TextLine(0);

                        String charResult   = "";
                        int    ControlIndex = 1;
                        for (int charIndex = 0; LineResult.NumberCharacters != charIndex; charIndex++)
                        {
                            CharacterResult characterResult = LineResult.Character(charIndex);
                            ICRChar         oChar           = new ICRChar(characterResult.Text, characterResult.Confidence);
                            for (int x = 0; x < characterResult.NumberResults; x++)
                            {
                                oChar.Results.Add(new ICRAlternateChar(characterResult.AlternateText(x), characterResult.AlternateConfidence(x)));
                            }

                            oChar.Area          = characterResult.Area;
                            oChar.NumberResults = characterResult.NumberResults;
                            Chars.Add(oChar);

                            charResult = charResult + characterResult.Text;
                            ControlIndex++;
                        }
                        Field.Result = charResult;
                        //MessageBox.Show(Field.Result);
                        Console.Out.WriteLine(Field.Result);
                    }
                }
                else
                {
                    Field.Result = "";
                }
            }
        }
Exemple #23
0
        public void Test()
        {
            #region Load Template
            try
            {
                InputImg.Image   = ImageX.FromFile(imagXpress1, @"I:\Templates\ICRTemplate.tif");
                frmTemplateImage = FormImage.FromHdib(InputImg.Image.ToHdib(false), true, formFix1);

                InputImg.Image  = ImageX.FromHdib(imagXpress1, (System.IntPtr) 0, true);
                OutputImg.Image = ImageX.FromHdib(imagXpress1, (System.IntPtr) 0, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion

            #region Load Image
            String ImageName = @"I:\Images\Order-0000000153.TIFF";
            try
            {
                InputImg.Image = ImageX.FromFile(imagXpress1, ImageName);
                frmFilledImage = FormImage.FromHdib(InputImg.Image.ToHdib(false), true, formFix1);

                OutputImg.Image = ImageX.FromHdib(imagXpress1, (System.IntPtr) 0, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            //it's all looking good, so we load our image into an ImageX object
            //imageXView1.Image = ImageX.FromFile(imagXpress1, strFileName);
            Processor prc = new Processor(imagXpress1, InputImg.Image);

            if (InputImg.Image.ImageXData.BitsPerPixel != 1)
            {
                prc.ColorDepth(1, PaletteType.Optimized, DitherType.NoDither);
                InputImg.Image = prc.Image;
            }



            #endregion

            #region Register Image
            try
            {
                regProcessor = new RegistrationProcessor(formFix1);

                regResult = regProcessor.RegisterToImage(frmFilledImage, frmTemplateImage);

                frmAlignedImage = regResult.AlignImage(frmFilledImage);

                InputImg.Image = ImageX.FromHdib(imagXpress1, frmAlignedImage.ToHdib(false), true);


                OutputImg.Image = InputImg.Image.Copy();
                OnPictureChanged(ICRType.ImageMatched);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion

            #region Preprocessing Image
            Processor proc = new Processor(imagXpress1, InputImg.Image);

            if (InputImg.Image.ImageXData.BitsPerPixel != 0)
            {
                proc.ColorDepth(1, 0, 0);
            }

            scanFix1.FromHdib(InputImg.Image.ToHdib(false));


            //Remove Lines
            LineRemovalOptions LineOpts = new LineRemovalOptions();
            LineOpts.MinimumLength = 20;
            scanFix1.RemoveLines(LineOpts);

            //Despeckle
            DespeckleOptions DespeckOpts = new DespeckleOptions();
            DespeckOpts.SpeckWidth  = 10;
            DespeckOpts.SpeckHeight = 14;
            scanFix1.Despeckle(DespeckOpts);

            //Deskew
            scanFix1.Deskew();

            //Comb options

            /*
             * comb = new PegasusImaging.WinForms.ScanFix5.CombRemovalOptions();
             *
             * comb.Area = new System.Drawing.Rectangle(AreaXBar.Value, AreaYBar.Value, AreaWBar.Value, AreaHBar.Value);
             * comb.CombHeight = CombHBar.Value;
             * comb.CombSpacing = SpaceBar.Value;
             * comb.HorizontalLineThickness = HBar.Value;
             * comb.VerticalLineThickness = VBar.Value;
             * comb.MinimumCombLength = LengthBar.Value;
             * comb.MinimumConfidence = ConfidenceBar.Value;
             *
             * scanFix1.RemoveCombs(comb);
             */

            //Smooth Options
            //scanFix1.SmoothObjects(SmoothBar.Value);


            //Blob Options

            /*
             * blob = new PegasusImaging.WinForms.ScanFix5.BlobRemovalOptions();
             *
             * blob.Area = new System.Drawing.Rectangle(BlobAreaXBar.Value, BlobAreaYBar.Value, AreaWidthBar.Value, AreaHeightBar.Value);
             * blob.MaximumPixelCount = MaxCountBar.Value;
             * blob.MinimumPixelCount = MinCountBar.Value;
             * blob.MinimumDensity = DensityBar.Value;
             *
             * scanFix1.RemoveBlobs(blob);
             */

            //Remove Dot Shading

            /*
             * dot = new PegasusImaging.WinForms.ScanFix5.DotShadingRemovalOptions();
             *
             * dot.DensityAdjustment = DotDensityBar.Value;
             * dot.MaximumDotSize = DotSizeBar.Value;
             * dot.HorizontalSizeAdjustment = HAdjBar.Value;
             * dot.VerticalSizeAdjustment = VAdjBar.Value;
             * dot.MinimumAreaHeight = DotHBar.Value;
             * dot.MinimumAreaWidth = DotWBar.Value;
             *
             * scanFix1.RemoveDotShading(dot);
             */


            //Remove Border Options

            /*
             * border = new PegasusImaging.WinForms.ScanFix5.BorderRemovalOptions();
             *
             * border.BorderSpeckSize = BSpeckBar.Value;
             * border.CropBorder = chkcrop.Checked;
             * border.DeskewBorder = chkdeskew.Checked;
             * border.MaximumPageHeight = MaxHeightBar.Value;
             * border.MaximumPageWidth = MaxWidthBar.Value;
             * border.MinimumConfidence = MinConBar.Value;
             * border.MinimumPageHeight = MinHeightBar.Value;
             * border.MinimumPageWidth = SpeckWidthBar.Value;
             * border.PageSpeckSize = PSpeckBar.Value;
             * border.Quality = SpeckQualityBar.Value;
             * border.ReplaceBorder = chkreplace.Checked;
             *
             * if (true)
             * {
             *  border.PadColor = System.Drawing.Color.FromArgb(0, 0, 0);
             * }
             * else
             * {
             *  border.PadColor = System.Drawing.Color.FromArgb(255, 255, 255);
             * }
             * scanFix1.RemoveBorder(border);
             */
            #endregion

            #region Read Fields

            InputImg.Image = ImageX.FromHdib(imagXpress1, scanFix1.ToHdib(false));


            // Set area and analyze field DIB
            SmartZone2.Reader.CharacterSet = CharacterSet.AllAlphas;
            Rectangle currentArea = new Rectangle(85, 170, 603, 79);
            SmartZone2.Reader.Area = currentArea;
            myTextBlockRes         = SmartZone2.Reader.AnalyzeField(InputImg.Image.ToHdib(false));


            if (myTextBlockRes.NumberTextLines > 0)
            {
                Boolean hasResult = true;

                LineResult = myTextBlockRes.TextLine(0);

                //   showBlockResult();
                //   showLineResult(0);
                //   showCharacterResult(0);
            }
            else
            {
                Boolean hasResult = false;
            }

            MessageBox.Show(myTextBlockRes.TextLine(0).Text);
            #endregion

            return;
        }
Exemple #24
0
        protected override bool PerformProcessingAction()
        {
            Processor proc = null;

            try
            {
                proc = new Processor(imagXpress1, imageXView1.Image.Copy());
                Helper.TransformIfGrayscale(proc.Image);
                DisposeOfOutputBitmaps(null);

                Point currentScrollPosition;
                if (imageXView2.Image == null)
                {
                    currentScrollPosition = imageXView1.ScrollPosition;
                }
                else
                {
                    currentScrollPosition = imageXView2.ScrollPosition;
                }

                proc.ColorSeparation((SeparationType)SeparationTypeComboBox.SelectedIndex, out bitmap1, out bitmap2, out bitmap3, out bitmap4);

                switch ((SeparationType)SeparationTypeComboBox.SelectedIndex)
                {
                case SeparationType.Rgb:
                {
                    if (RedRgbRadioButton.Checked)
                    {
                        outputBitmap = bitmap1;
                        DisposeOfOutputBitmaps(bitmap1);
                    }
                    else if (GreenRgbRadioButton.Checked)
                    {
                        outputBitmap = bitmap2;
                        DisposeOfOutputBitmaps(bitmap2);
                    }
                    else if (BlueRgbRadioButton.Checked)
                    {
                        outputBitmap = bitmap3;
                        DisposeOfOutputBitmaps(bitmap3);
                    }

                    break;
                }

                case SeparationType.Hsl:
                {
                    if (HueRadioButton.Checked)
                    {
                        outputBitmap = bitmap1;
                        DisposeOfOutputBitmaps(bitmap1);
                    }
                    else if (SaturationRadioButton.Checked)
                    {
                        outputBitmap = bitmap2;
                        DisposeOfOutputBitmaps(bitmap2);
                    }
                    else if (LuminanceRadioButton.Checked)
                    {
                        outputBitmap = bitmap3;
                        DisposeOfOutputBitmaps(bitmap3);
                    }

                    break;
                }

                case SeparationType.Cmy:
                {
                    if (CyanCmyRadioButton.Checked)
                    {
                        outputBitmap = bitmap1;
                        DisposeOfOutputBitmaps(bitmap1);
                    }
                    else if (MagentaCmyRadioButton.Checked)
                    {
                        outputBitmap = bitmap2;
                        DisposeOfOutputBitmaps(bitmap2);
                    }
                    else if (YellowCmyRadioButton.Checked)
                    {
                        outputBitmap = bitmap3;
                        DisposeOfOutputBitmaps(bitmap3);
                    }

                    break;
                }

                case SeparationType.Cmyk:
                {
                    if (CyanCmykRadioButton.Checked)
                    {
                        outputBitmap = bitmap1;
                        DisposeOfOutputBitmaps(bitmap1);
                    }
                    else if (MagentaCmykRadioButton.Checked)
                    {
                        outputBitmap = bitmap2;
                        DisposeOfOutputBitmaps(bitmap2);
                    }
                    else if (YellowCmykRadioButton.Checked)
                    {
                        outputBitmap = bitmap3;
                        DisposeOfOutputBitmaps(bitmap3);
                    }
                    else if (BlackCmykRadioButton.Checked)
                    {
                        outputBitmap = bitmap4;
                        DisposeOfOutputBitmaps(bitmap4);
                    }

                    break;
                }

                case SeparationType.Rgba:
                {
                    if (RedRgbaRadioButton.Checked)
                    {
                        outputBitmap = bitmap1;
                        DisposeOfOutputBitmaps(bitmap1);
                    }
                    else if (GreenRgbaRadioButton.Checked)
                    {
                        outputBitmap = bitmap2;
                        DisposeOfOutputBitmaps(bitmap2);
                    }
                    else if (BlueRgbaRadioButton.Checked)
                    {
                        outputBitmap = bitmap3;
                        DisposeOfOutputBitmaps(bitmap3);
                    }
                    else if (AlphaRgbaRadioButton.Checked)
                    {
                        outputBitmap = bitmap4;
                        DisposeOfOutputBitmaps(bitmap4);
                    }

                    break;
                }
                }

                using (ImageX img = ImageX.FromBitmap(imagXpress1, outputBitmap))
                {
                    UpdateOutputImage(img.Copy());
                }

                imageXView2.ScrollPosition = currentScrollPosition;

                return(true);
            }
            catch (ProcessorException ex)
            {
                MessageBox.Show(ex.Message, Constants.processingErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (ImageXException ex)
            {
                MessageBox.Show(ex.Message, Constants.processingErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            finally
            {
                if (proc != null)
                {
                    if (proc.Image != null)
                    {
                        proc.Image.Dispose();
                        proc.Image = null;
                    }
                    proc.Dispose();
                    proc = null;
                }
            }
        }