Example #1
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;
             }
         }
     }
 }
Example #2
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);
                }
            }
        }
Example #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();
            }
        }
Example #4
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);
            }
        }
Example #5
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);
            }
        }
Example #6
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);
        }
Example #7
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);
            }
        }
Example #8
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++;
            }
        }
Example #9
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);
        }
Example #10
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;
            }
        }
Example #11
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;
        }
Example #12
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;
                }
            }
        }