Exemplo n.º 1
0
        /// <summary>
        /// Creates an image.
        /// </summary>
        /// <returns>An image.</returns>
        public VintasoftImage CreateImage()
        {
            // crete image
            VintasoftImage image = new VintasoftImage(_imageSize, _pixelFormat);


            // create palette

            Palette palette = null;

            if (_pixelFormat == PixelFormat.Indexed1)
            {
                palette = Palette.CreateBlackWhitePalette();
            }
            else if (_pixelFormat == PixelFormat.Indexed4)
            {
                palette = Palette.CreateGrayscalePalette(16);
            }
            else if (_pixelFormat == PixelFormat.Indexed8)
            {
                palette = Palette.CreateGrayscalePalette();
            }
            // if palette must be updates
            if (palette != null)
            {
                image.Palette.SetColors(palette.GetAsArray());
            }


            return(image);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AdaptiveBinarizeForm"/> class.
 /// </summary>
 /// <param name="viewer">The image viewer for image preview.</param>
 /// <param name="image">The image.</param>
 public BrightnessContrastForm(ImageViewer viewer, VintasoftImage image)
     : base(viewer,
            "Brightness / contrast",
            new ImageProcessingParameter("Brightness", -100, 100, 0),
            new ImageProcessingParameter("Contrast", -100, 100, 0))
 {
 }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the new rectangle of an object in pixels.
        /// </summary>
        /// <param name="rect">The new rectangle of an object in pixels.</param>
        protected override void SetRect(Rectangle rect)
        {
            VintasoftImage image = _imageViewer.Image;

            if (image != null)
            {
                // get transform from control to the device independent pixels (DIP)
                AffineMatrix matrix = _imageViewer.GetTransformFromControlToDip();

                // convert location to the DIP
                PointF locationInDip = PointFAffineTransform.TransformPoint(matrix, rect.Location);

                if (HideContentOnTransform)
                {
                    // if comment control content is visible
                    if (!_isCommentControlContentHidden)
                    {
                        // hide comment control content
                        UpdateCommentControlContentVisibility(false);
                        _isCommentControlContentHidden = true;
                    }
                }

                // update comment bounding box
                CommentControl.Comment.BoundingBox = new RectangleF(locationInDip, rect.Size);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reloads the images in the specified image viewer.
        /// </summary>
        /// <param name="imageViewer">The image viewer.</param>
        public static void ReloadImagesInViewer(ImageViewerBase imageViewer)
        {
            try
            {
                ImageCollection images       = imageViewer.Images;
                int             focusedIndex = imageViewer.FocusedIndex;
                VintasoftImage  focusedImage = null;
                if (focusedIndex >= 0 && focusedIndex < images.Count)
                {
                    focusedImage = images[focusedIndex];
                    if (focusedImage != null)
                    {
                        focusedImage.Reload(true);
                    }
                }

                foreach (VintasoftImage nextImage in imageViewer.Images)
                {
                    if (nextImage != focusedImage)
                    {
                        nextImage.Reload(true);
                    }
                }
            }
            catch (Exception e)
            {
                ShowErrorMessage(e);
            }
        }
        /// <summary>
        /// Adds the annotation with comment.
        /// </summary>
        public void AddNewComment()
        {
            // get comment annotation image
            VintasoftImage image = DemosResourcesManager.GetResourceAsImage(
                "DemosCommonCode.Annotation.Comments.AnnotationCommentBuilder.CommentIcon.png");

            // create comment annotation data
            EmbeddedImageAnnotationData annotationData = new EmbeddedImageAnnotationData(image);
            Resolution resolution = _annotationVisualTool.ImageViewer.Image.Resolution;

            annotationData.Size = new SizeF(
                (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(image.Width, UnitOfMeasure.Pixels, resolution.Horizontal),
                (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(image.Height, UnitOfMeasure.Pixels, resolution.Vertical));
            annotationData.Border = false;

            // create comment
            annotationData.Comment      = new AnnotationComment(Color.Yellow, Environment.UserName);
            annotationData.Comment.Type = "Comment";

            // build annotation
            _annotationVisualTool.AnnotationBuildingFinished += AnnotationVisualTool_AnnotationBuildingFinished;
            RectangleAnnotationView view = (RectangleAnnotationView)_annotationVisualTool.AddAndBuildAnnotation(annotationData);

            view.Builder = new RectangularObjectMoveBuilder(view, annotationData.Size);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetHistogramForm"/> class.
        /// </summary>
        /// <param name="image">The analyzed image.</param>
        /// <param name="imageRegion">Selected image region.</param>
        /// <param name="expandSupportedPixelFormats">A value indicating whether the processing command need to
        /// convert the processing image to the nearest pixel format.</param>
        public GetHistogramForm(
            VintasoftImage image,
            Rectangle imageRegion,
            bool expandSupportedPixelFormats)
        {
            InitializeComponent();

            _expandSupportedPixelFormats = expandSupportedPixelFormats;
            _image       = image;
            _imageRegion = imageRegion;

            if (imageRegion.Size.IsEmpty)
            {
                _pixelCount = image.Width * image.Height;
            }
            else
            {
                _pixelCount = imageRegion.Width * imageRegion.Height;
            }

            _histogramImage = GetHistogramImage(_image, _imageRegion, _histogramType);
            histogramImagePictureBox.Image = _histogramImage.GetAsBitmap();

            histogramTypeComboBox.SelectedIndex = 0;
            pixelCountLabel.Text = string.Format("Pixels: {0}", _pixelCount);
        }
        /// <summary>
        /// Returns a value, which determines that the image edge is visible.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="imageEdge">The image edge.</param>
        /// <returns>
        /// <b>true</b> - if image edge is visible.
        /// <b>false</b> - if image edge is not visible.
        /// </returns>
        private bool GetIsImageEdgeVisible(VintasoftImage image, Vintasoft.Imaging.UI.AnchorType imageEdge)
        {
            // get image viewer state for the image
            Vintasoft.Imaging.UI.ImageViewerState focusedImageViewerState = ImageViewer.GetViewerState(image);

            // get the visible image rectangle in image viewer
            RectangleF imageVisibleRect;

            if (ImageViewer.IsMultipageDisplayMode)
            {
                imageVisibleRect = ImageViewer.ClientRectangle;
            }
            else
            {
                imageVisibleRect = focusedImageViewerState.ImageVisibleRect;
            }

            // get the image rectangle in image viewer
            RectangleF imageRect;

            if (ImageViewer.IsMultipageDisplayMode)
            {
                imageRect = focusedImageViewerState.ImageBoundingBox;
            }
            else
            {
                imageRect = new RectangleF(0, 0, ImageViewer.Image.Width, ImageViewer.Image.Height);
            }
            if (imageRect == RectangleF.Empty)
            {
                return(false);
            }

            // get the image "anchor" line
            RectangleF imageLine = RectangleF.Empty;

            if (imageEdge == Vintasoft.Imaging.UI.AnchorType.Bottom)
            {
                // get bottom line of image
                imageLine = new RectangleF(imageRect.X, imageRect.Y + imageRect.Height - 1, imageRect.Width, 1);
            }
            else if (imageEdge == Vintasoft.Imaging.UI.AnchorType.Top)
            {
                // get top line of image
                imageLine = new RectangleF(imageRect.X, imageRect.Y, imageRect.Width, 1);
            }
            else if (imageEdge == Vintasoft.Imaging.UI.AnchorType.Left)
            {
                // get left line of image
                imageLine = new RectangleF(0, 0, 1, ImageViewer.Image.Height);
            }
            else if (imageEdge == Vintasoft.Imaging.UI.AnchorType.Right)
            {
                // get right line of image
                imageLine = new RectangleF(ImageViewer.Image.Width - 1, 0, 1, ImageViewer.Image.Height);
            }

            // return a value that indicates whether the visible rectangle intersects with image line
            return(imageVisibleRect.IntersectsWith(imageLine));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Determines whether specified processing command can process the specified image.
        /// </summary>
        /// <param name="command">Image processing command.</param>
        /// <param name="image">Image to process.</param>
        /// <returns>
        /// <b>true</b> - processing command can process image;
        /// otherwise, <b>false</b>.
        /// </returns>
        private bool CommandCanProcessImage(ProcessingCommandBase command, VintasoftImage image)
        {
            bool needConvertToSupportedPixelFormat = command.ExpandSupportedPixelFormats;

            command.ExpandSupportedPixelFormats = ExpandSupportedPixelFormats;
            PixelFormat outputPixelFormat = command.GetOutputPixelFormat(image);

            command.ExpandSupportedPixelFormats = needConvertToSupportedPixelFormat;

            if (outputPixelFormat != PixelFormat.Undefined)
            {
                return(true);
            }

            System.Text.StringBuilder        sb      = new System.Text.StringBuilder();
            ReadOnlyCollection <PixelFormat> formats = command.SupportedPixelFormats;

            for (int i = 0; i < formats.Count; i++)
            {
                sb.Append(" -");
                sb.Append(formats[i].ToString());
                sb.AppendLine(";");
            }
            string supportedPixelFormatNames = sb.ToString();

            string message = string.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                "{0}: unsupported pixel format - {1}.\n\nProcessing command supports only the following pixel formats:\n{2}\nPlease convert the image to supported pixel format first.",
                command.Name,
                image.PixelFormat,
                supportedPixelFormatNames);

            DemosTools.ShowErrorMessage("Image processing exception", message);
            return(false);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Executes the SetAlphaChannelCommand command.
        /// </summary>
        public void ExecuteSetAlphaChannelCommand()
        {
            if (_openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            VintasoftImage maskImage;

            try
            {
                maskImage = new VintasoftImage(_openFileDialog.FileName);
            }
            catch (Exception ex)
            {
                DemosTools.ShowErrorMessage("SetAlphaChannelMaskCommand", ex);
                return;
            }

            SetAlphaChannelMaskCommand command = new SetAlphaChannelMaskCommand(maskImage);

            ExecuteProcessingCommand(command, false);

            maskImage.Dispose();
        }
Exemplo n.º 10
0
 /// <summary>
 /// Updates the form when the image pixel is selected.
 /// </summary>
 /// <param name="x">Pixel X coordinate.</param>
 /// <param name="y">Pixel Y coordinate.</param>
 internal void SelectPixel(int x, int y)
 {
     if (x >= 0 && y >= 0)
     {
         VintasoftImage image = _viewer.Image;
         if (x < image.Width && y < image.Height)
         {
             try
             {
                 ColorBase pixelColor = _viewer.Image.GetPixelColor(x, y);
                 ShowSelectedPixelColor(x, y, pixelColor);
             }
             catch (Exception e)
             {
                 DemosTools.ShowErrorMessage(e);
             }
             return;
         }
     }
     selectedPixelLabel.Text           = "Selected Pixel: click on image to select";
     argbPanel.Visible                 = false;
     indexedPanel.Visible              = false;
     gray16Panel.Visible               = false;
     selectedPixelColorPanel.BackColor = Color.Transparent;
 }
Exemplo n.º 11
0
 public void Recognize(TesseractOcrSettings settings, VintasoftImage image)
 {
     using (TesseractOcr tesseractOcr = new TesseractOcr())
     {
         tesseractOcr.Init(settings);
         tesseractOcr.SetImage(image);
         OcrPage ocrResult = tesseractOcr.Recognize();
         _editor.EditorResult(ocrResult);
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Returns center point of image viewer in coordinate space of specified image.
        /// </summary>
        /// <param name="image">An image.</param>
        /// <returns>
        /// Center point of image viewer in coordinate space of specified image.
        /// </returns>
        private PointF GetCenterPoint(VintasoftImage image)
        {
            // get old visible point
            PointF centerPoint = new PointF(ImageViewer.ClientSize.Width / 2.0f, ImageViewer.ClientSize.Height / 2.0f);
            // get transform from image space to viewer space
            AffineMatrix pointTransfrom = ImageViewer.GetTransformFromControlToImage(image);

            // transform the point
            return(PointFAffineTransform.TransformPoint(pointTransfrom, centerPoint));
        }
Exemplo n.º 13
0
 /// <summary>
 /// Returns the loading error string.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <returns>The loading error string.</returns>
 public static object GetShortLoadingErrorString(VintasoftImage image)
 {
     if (!image.LoadingError)
     {
         return("");
     }
     if (image.LoadingErrorString.Length <= 150)
     {
         return(image.LoadingErrorString);
     }
     return(image.LoadingErrorString.Substring(0, 150) + "...");
 }
        /// <summary>
        /// Sets the annotation comment location.
        /// </summary>
        /// <param name="comment">The comment.</param>
        private void SetAnnotationCommentLocation(AnnotationComment comment)
        {
            VintasoftImage focusedImage = _annotationVisualTool.ImageViewer.Image;

            if (focusedImage != null)
            {
                float x = (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(focusedImage.Width, UnitOfMeasure.Pixels, focusedImage.Resolution.Horizontal);
                comment.BoundingBox = new RectangleF(
                    x, comment.Annotation.Location.Y,
                    AnnotationComment.DefaultCommentSize.Width, AnnotationComment.DefaultCommentSize.Height);
            }
        }
        /// <summary>
        /// Rotates image with annotations.
        /// </summary>
        /// <param name="annotationViewer">The annotation viewer.</param>
        /// <param name="undoManager">The undo manager.</param>
        /// <param name="dataStorage">The data storage.</param>
        public static void RotateImageWithAnnotations(AnnotationViewer annotationViewer, CompositeUndoManager undoManager, IDataStorage dataStorage)
        {
            // cancel annotation building
            annotationViewer.CancelAnnotationBuilding();

            // create rotate image dialog
            using (RotateImageWithAnnotationsForm dialog = new RotateImageWithAnnotationsForm(annotationViewer.Image.PixelFormat))
            {
                // if image with annotation must be rotated
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // if undo manager is enabled
                    if (undoManager.IsEnabled)
                    {
                        // begin the composite undo action
                        undoManager.BeginCompositeAction("Rotate image with annotations");

                        // if undo manager does not contain the history for current image
                        if (!undoManager.ContainsActionForSourceObject(annotationViewer.Image))
                        {
                            // create change undo action
                            ChangeImageUndoAction originalImageAction = new ChangeImageUndoAction(dataStorage, annotationViewer.Image);
                            undoManager.AddAction(originalImageAction, null);
                        }
                        try
                        {
                            // create change undo action
                            ChangeImageUndoAction action = new ChangeImageUndoAction(dataStorage, annotationViewer.Image, "Rotate");
                            // clone focused image
                            using (VintasoftImage previousImage = (VintasoftImage)annotationViewer.Image.Clone())
                            {
                                // rotate focused image with annotations
                                RotateFocusedImageWithAnnotations(annotationViewer, (float)dialog.Angle, dialog.BorderColorType, dialog.SourceImagePixelFormat);

                                // add action to the undo manager
                                undoManager.AddAction(action, previousImage);
                            }
                        }
                        finally
                        {
                            // end the composite undo action
                            undoManager.EndCompositeAction();
                        }
                    }
                    else
                    {
                        // rotate focused image with annotations
                        RotateFocusedImageWithAnnotations(annotationViewer, (float)dialog.Angle, dialog.BorderColorType, dialog.SourceImagePixelFormat);
                    }
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Konvertiert die PDF-Datei in Jpeg-Dateien.
        /// Gibt eine liste mit den Pfaden der Jpeg-Dateien zurück.
        /// </summary>
        public List <string> ConvertPDFToImage(string pathFolder, bool tempPrefix, DocumentParam param)
        {
            List <string> list = new List <string>();

            try
            {
                if (string.CompareOrdinal(pathFolder, string.Empty) == 0)
                {
                    return(list);
                }

                FileInfo fileInfo = new FileInfo(param.FilePath);

                if (fileInfo.Exists == false)
                {
                    return(list);
                }



                FilesFunctions.DeleteFilesInFolder(pathFolder, Jpeg);

                using (PdfDocument pdfDocument = new PdfDocument(param.FilePath, true))
                {
                    //pdfDocument.RenderingSettings.Resolution = new Resolution(150, 150);
                    JpegEncoder jpeGencoder = new JpegEncoder
                    {
                        Settings = { Quality = param.Quality, SaveAsGrayscale = false }
                    };


                    for (int pageCount = 0; pageCount < pdfDocument.Pages.Count; pageCount++)
                    {
                        string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, tempPrefix, Jpeg);
                        // get image of PDF page as VintasoftImage object
                        using (VintasoftImage vsImage = pdfDocument.Pages[pageCount].Render())
                        {
                            // save VintasoftImage object as JPEG file
                            vsImage.Save(tempName, jpeGencoder);
                            list.Add(tempName);
                        }
                    }
                }
                return(list);
            }
            catch (Exception ex)
            {
                FileLogger.FileLogger.Instance.WriteExeption(ex);
                return(list);
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Sets the rendering settings if necessary.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="encoder">The encoder.</param>
 /// <param name="defaultRenderingSettings">The default rendering settings.</param>
 public static void SetRenderingSettingsIfNeed(
     VintasoftImage image, EncoderBase encoder, RenderingSettings defaultRenderingSettings)
 {
     if (encoder == null || !(encoder is IPdfEncoder))
     {
         if (image.IsVectorImage)
         {
             RenderingSettingsForm settingsForm = new RenderingSettingsForm(defaultRenderingSettings.CreateClone());
             if (settingsForm.ShowDialog() == DialogResult.OK)
             {
                 image.RenderingSettings = settingsForm.RenderingSettings;
             }
         }
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Handler of the ProcessingCommandBase.Finished event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ImageProcessedEventArgs"/> instance containing the event data.</param>
        void command_Finished(object sender, ImageProcessedEventArgs e)
        {
            ProcessingCommandBase command = (ProcessingCommandBase)sender;

            command.Finished -= new EventHandler <ImageProcessedEventArgs>(command_Finished);

            if (command is ParallelizingProcessingCommand)
            {
                command = ((ParallelizingProcessingCommand)command).ProcessingCommand;
            }

            if (command is OverlayCommand ||
                command is OverlayWithBlendingCommand ||
                command is OverlayMaskedCommand)
            {
                if (_overlayImage != null)
                {
                    // dispose the temporary overlay image because the processing command is finished
                    _overlayImage.Dispose();
                    _overlayImage = null;
                }
                if (_maskImage != null)
                {
                    // dispose the temporary mask image because the processing command is finished
                    _maskImage.Dispose();
                    _maskImage = null;
                }
            }

            if (command is ImageComparisonCommand)
            {
                if (_comparisonImage != null)
                {
                    _comparisonImage.Dispose();
                    _comparisonImage = null;
                }
            }

            _isImageProcessingWorking = false;

            if (_imageProcessingUndoMonitor != null)
            {
                _imageProcessingUndoMonitor.Dispose();
                _imageProcessingUndoMonitor = null;
            }

            OnImageProcessingCommandFinished((ProcessingCommandBase)sender, e);
        }
        /// <summary>
        /// Removes the visual tool image.
        /// </summary>
        private void RemoveVisualToolImage()
        {
            // get overlay tool
            OverlayImageTool overlayImageTool = (OverlayImageTool)VisualTool;

            // if image of overlay tool is specified
            if (overlayImageTool.Image != null)
            {
                // get image
                VintasoftImage image = overlayImageTool.Image;
                // reset image of overlay tool
                overlayImageTool.Image = null;
                // remove image
                image.Dispose();
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Handles the Click event of CaptureImageButton object.
 /// </summary>
 private void captureImageButton_Click(object sender, EventArgs e)
 {
     if (SnapshotViewer != null)
     {
         // get current image
         VintasoftImage image = videoPreviewImageViewer.Image;
         // if current image is specified
         if (image != null)
         {
             // add image to snapshot viewer
             SnapshotViewer.Images.Add((VintasoftImage)image.Clone());
             // change focused index to current image
             SnapshotViewer.FocusedIndex = SnapshotViewer.Images.Count - 1;
         }
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Returns distance between point and image rectangle.
        /// </summary>
        /// <param name="point">A point in image viewer space.</param>
        /// <param name="image">An image.</param>
        /// <returns>Distance between point and image rectangle.</returns>
        private float GetDistanceBetweenPointAndImageRect(PointF point, VintasoftImage image)
        {
            AffineMatrix transformMatrix = ImageViewer.GetTransformFromImageToControl(image);
            // get image rectangle
            RectangleF      imageRect      = new RectangleF(0, 0, image.Width, image.Height);
            PointFTransform pointTransform = PointFAffineTransform.FromMatrix(transformMatrix);

            imageRect = PointFAffineTransform.TransformBoundingBox(pointTransform, imageRect);

            PointF imagePoint = PointF.Empty;

            // get X coordinate of point on image
            if (point.X < imageRect.X)
            {
                imagePoint.X = imageRect.X;
            }
            else if (point.X > imageRect.X + imageRect.Width)
            {
                imagePoint.X = imageRect.X + imageRect.Width;
            }
            else
            {
                imagePoint.X = point.X;
            }

            // get Y coordinate of point on image
            if (point.Y < imageRect.Y)
            {
                imagePoint.Y = imageRect.Y;
            }
            else if (point.Y > imageRect.Y + imageRect.Height)
            {
                imagePoint.Y = imageRect.Y + imageRect.Height;
            }
            else
            {
                imagePoint.Y = point.Y;
            }

            // calculate distance
            float dx = (point.X - imagePoint.X);
            float dy = (point.Y - imagePoint.Y);
            float distanceBetweenImageAndPoint = dx * dx + dy * dy;

            return(distanceBetweenImageAndPoint);
        }
Exemplo n.º 22
0
        //public bool Colour { get; set; }
        //public int Compression { get; set; }
        //public bool KeepOriginal { get; set; }

        #region Jpeg

        /// <summary>
        /// Von dem PDF-Dokument wird die erste Seite in Jpeg konvertiert und gespeichert.
        /// die funktion liefert den Path zu der neue Datei zurück.
        /// </summary>
        public string GetFirstPageAsImageFromDocument(DocumentParam param)
        {
            try
            {
                string   fileName = string.Empty;
                FileInfo fileInfo = new FileInfo(param.FilePath);

                if (fileInfo.Exists == false)
                {
                    return(fileName);
                }

                string pathFolder = Path.GetTempPath();

                using (PdfDocument pdfDocument = new PdfDocument(param.FilePath, true))
                {
                    pdfDocument.RenderingSettings.Resolution = new Resolution(150, 150);
                    JpegEncoder jpeGencoder = new JpegEncoder
                    {
                        Settings = { Quality = param.Quality, SaveAsGrayscale = false }
                    };


                    for (int pageCount = 0; pageCount < 1; pageCount++)
                    {
                        string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, true, Jpeg);
                        // get image of PDF page as VintasoftImage object
                        using (VintasoftImage vsImage = pdfDocument.Pages[pageCount].Render())
                        {
                            // save VintasoftImage object as JPEG file
                            vsImage.Save(tempName, jpeGencoder);
                            fileName = tempName;
                        }
                    }
                }

                return(fileName);
            }
            catch (Exception ex)
            {
                FileLogger.FileLogger.Instance.WriteExeption(ex);
                return(string.Empty);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Executes the OverlayCommand command.
        /// </summary>
        public void ExecuteOverlayWithBlendingCommand()
        {
            // create the processing command
            OverlayWithBlendingCommand command = new OverlayWithBlendingCommand();

            // set properties of command
            PropertyGridForm propertyGridForm = new PropertyGridForm(command, "Overlay with Blending Command Properties", true);

            if (propertyGridForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // save a reference to the overlay image, image will be disposed when command is finished
            _overlayImage = command.OverlayImage;

            // execute the command
            ExecuteProcessingCommand(command, true);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Executes the DrawImageCommand command.
        /// </summary>
        public void ExecuteDrawImageCommand()
        {
            // create the processing command
            DrawImageCommand command = ImageProcessingCommandFactory.CreateDrawImageCommand(_viewer.Image);

            // set properties of command
            PropertyGridForm propertyGridForm = new PropertyGridForm(command, "Draw Image Command Properties", true);

            if (propertyGridForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // save a reference to the overlay image, image will be disposed when command is finished
            _overlayImage = command.OverlayImage;

            // execute the command
            ExecuteProcessingCommand(command, true);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Executes the ImageComparisonCommand command.
        /// </summary>
        public void ExecuteComparisonCommand()
        {
            // create the processing command
            ImageComparisonCommand command = new ImageComparisonCommand();

            // set properties of command
            PropertyGridForm propertyGridForm = new PropertyGridForm(command, "Image Comparison Command Properties", true);

            if (propertyGridForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // save a reference to the comparison image, image will be disposed when command is finished
            _comparisonImage = command.Image;

            // execute the command
            ExecuteProcessingCommand(command, true);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Sets focus to the visible image.
        /// </summary>
        /// <remarks>
        /// Focus will be changed if focused image is not visible.
        /// </remarks>
        private void SetFocusToVisibleImage()
        {
            // if focused image is not visible
            if (ImageViewer.ViewerState.ImageVisibleRect == RectangleF.Empty)
            {
                // get visible images
                VintasoftImage[] visibleImages = ImageViewer.GetVisibleImages();

                // get central point of image viewer
                PointF centerPoint = new PointF(ImageViewer.ClientSize.Width / 2.0f, ImageViewer.ClientSize.Height / 2.0f);

                float minDistance = ImageViewer.ClientSize.Width * ImageViewer.ClientSize.Width +
                                    ImageViewer.ClientSize.Height * ImageViewer.ClientSize.Height;
                VintasoftImage minDistanceImage = null;

                // for each visible image
                foreach (VintasoftImage image in visibleImages)
                {
                    // calculate distance between central point and image rectangle
                    float distanceBetweenImageAndPoint = GetDistanceBetweenPointAndImageRect(centerPoint, image);

                    if (distanceBetweenImageAndPoint < minDistance)
                    {
                        minDistance      = distanceBetweenImageAndPoint;
                        minDistanceImage = image;
                    }
                }

                // if there is visible image
                if (minDistanceImage != null)
                {
                    _isPageChanging = true;
                    // get index of visible image
                    int indexOfVisibleImage = ImageViewer.Images.IndexOf(minDistanceImage);

                    // set focus to visible image
                    ChangeFocusedImage(indexOfVisibleImage);

                    _isPageChanging = false;
                }
            }
        }
        /// <summary>
        /// Copies image with annotations to the clipboard.
        /// </summary>
        /// <param name="annotationViewer">The annotation viewer.</param>
        public static void CopyImageToClipboard(AnnotationViewer annotationViewer)
        {
            // if focused image is not correct
            if (!CheckImage(annotationViewer))
            {
                return;
            }

            try
            {
                // create image with annotations
                using (VintasoftImage image = annotationViewer.AnnotationViewController.GetImageWithAnnotations(annotationViewer.FocusedIndex))
                    // copy image to the clipboard
                    Clipboard.SetImage(image.GetAsBitmap());
            }
            catch (Exception ex)
            {
                DemosTools.ShowErrorMessage(ex);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Updates the captured image in image viewer.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ImageCaptureCompletedEventArgs"/> instance containing the event data.</param>
        private void CaptureSource_CaptureCompleted(object sender, ImageCaptureCompletedEventArgs e)
        {
            // save reference to the previously captured image
            VintasoftImage oldImage = videoPreviewImageViewer.Image;

            // get captured image
            VintasoftImage newImage = e.GetCapturedImage();

            // apply processing
            if (_processingCommand != null)
            {
                _processingCommand.ExecuteInPlace(newImage);
            }

            // show captured image in the preview viewer
            videoPreviewImageViewer.Image = newImage;

            // if previously captured image is exist
            if (oldImage != null)
            {
                // dispose previously captured image
                oldImage.Dispose();
            }

            // if capture source is started
            if (_imageCaptureSource.State == ImageCaptureState.Started)
            {
                // sleep...
                if (_imageCaptureTimeout > 0)
                {
                    Thread.Sleep(_imageCaptureTimeout);
                }
                // if capture source is started
                if (_imageCaptureSource.State == ImageCaptureState.Started)
                {
                    // initialize new image capture request
                    _imageCaptureSource.CaptureAsync();
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Updates barcode image.
        /// </summary>
        private void WriterSettings_Changed(object sender, EventArgs e)
        {
#if !REMOVE_BARCODE_SDK
            if (_barcodeWriterToolForm == null)
            {
                return;
            }
            BarcodeWriterToolForm form = _barcodeWriterToolForm as BarcodeWriterToolForm;
            try
            {
                BarcodeWriterTool tool = (BarcodeWriterTool)VisualTool;
                using (VintasoftImage barcodeImage = tool.GetBarcodeImage())
                {
                    form.BarcodeImage = barcodeImage.GetAsBitmap();
                }
            }
            catch (WriterSettingsException)
            {
                form.BarcodeImage = null;
            }
#endif
        }
Exemplo n.º 30
0
        /// <summary>
        /// Returns "Crop to custom selection" composite command.
        /// </summary>
        /// <param name="path">Custom selection path.</param>
        /// <param name="pathBounds">Selection path bounds.</param>
        /// <param name="crop">Crop command.</param>
        /// <returns>Crop command for custom selection.</returns>
        ProcessingCommandBase GetCropToPathCommand(
            GraphicsPath path,
            RectangleF pathBounds,
            CropCommand crop)
        {
            Rectangle viewerImageRect = new Rectangle(0, 0, _viewer.Image.Width, _viewer.Image.Height);

            crop.RegionOfInterest = new RegionOfInterest(GetBoundingRect(RectangleF.Intersect(pathBounds, viewerImageRect)));

            // overlay command
            _overlayImage = crop.Execute(_viewer.Image);
            OverlayCommand overlay = new OverlayCommand(_overlayImage);

            // overlay with path command
            ProcessPathCommand overlayWithPath = new ProcessPathCommand(overlay, path);

            // clear image command
            ClearImageCommand clearImage = new ClearImageCommand(Color.Transparent);

            // create composite command: clear, overlay with path, crop
            return(new CompositeCommand(clearImage, overlayWithPath, crop));
        }