Ejemplo n.º 1
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;
                }
            }
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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;
                }
            }
        }
Ejemplo n.º 4
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 = "";
                }
            }
        }