Exemplo n.º 1
0
        private void ApplyFilter()
        {
            if (_polyPoints.Count == 4 && _firstPointSelected)
            {
                List <LeadPoint> PolyPoints = new List <LeadPoint>();
                for (int i = 0; i < 4; i++)
                {
                    PolyPoints.Add(new LeadPoint(_polyPoints[i].X, _polyPoints[i].Y));
                }
                KeyStoneCommand command = new KeyStoneCommand(PolyPoints.ToArray());
                try
                {
                    command.Run(_viewer.Image);
                }
                catch (System.Exception ex)
                {
                    Messager.ShowError(this, ex);
                    return;
                }

                _viewer.Cursor = Cursors.Default;
#if !LEADTOOLS_V20_OR_LATER
                _viewer.Image = command.TransformedBitmap.Clone();
#else
                _viewer.Image = command.TransformedImage.Clone();
#endif // #if !LEADTOOLS_V20_OR_LATER
                _viewer.Invalidate();
                _firstPointSelected = false;
                _btnReset.Enabled   = true;
                _btnApply.Enabled   = false;
            }
        }
Exemplo n.º 2
0
        private void ApplyFilter()
        {
            if (_polyPoints.Count == 4 && _firstPointSelected)
            {
                _applied = true;
                LeadPoint[] PolyPoints = new LeadPoint[4];
                for (int i = 0; i < 4; i++)
                {
                    PolyPoints[i].X = _polyPoints[i].X;
                    PolyPoints[i].Y = _polyPoints[i].Y;
                }

                _viewer.Image.MakeRegionEmpty();

                KeyStoneCommand command = new KeyStoneCommand(PolyPoints);

                try
                {
                    command.Run(_viewer.Image);
                }
                catch (System.Exception ex)
                {
                    Messager.ShowError(this, ex);
                    return;
                }

                _viewer.Cursor = Cursors.Default;
#if !LEADTOOLS_V20_OR_LATER
                if (command.TransformedBitmap != null)
                {
                    _viewer.Image = command.TransformedBitmap.Clone();
                }
#else
                if (command.TransformedImage != null)
                {
                    _viewer.Image = command.TransformedImage.Clone();
                }
#endif // #if !LEADTOOLS_V20_OR_LATER

                _viewer.Invalidate();
                _form.Invalidate();
                _firstPointSelected = false;
                _btnReset.Enabled   = true;
                _btnApply.Enabled   = false;
            }
        }
        public RasterImage ApplyDeskew()
        {
            if (ImageViewer == null || ImageViewer.ActiveItem.Image == null)
            {
                return(null);
            }

            LeadPoint[] polygonPoints = new LeadPoint[4];
            polygonPoints[0] = TopLeft;
            polygonPoints[1] = TopRight;
            polygonPoints[2] = BottomRight;
            polygonPoints[3] = BottomLeft;
            KeyStoneCommand command = new KeyStoneCommand(polygonPoints);

            command.Run(ImageViewer.ActiveItem.Image);

            return(command.TransformedImage);
        }
Exemplo n.º 4
0
        private void ApplyFilter()
        {
            using (WaitCursor wait = new WaitCursor())
            {
                if (_polyPoints.Count == 4 && _firstPointSelected)
                {
                    _applied = true;
                    LeadPoint[] PolyPoints = new LeadPoint[4];
                    for (int i = 0; i < 4; i++)
                    {
                        PolyPoints[i].X = _polyPoints[i].X;
                        PolyPoints[i].Y = _polyPoints[i].Y;
                    }

                    _viewer.Image.MakeRegionEmpty();

                    RasterCommand command = null;
                    if (!_manualPerspectiveDeskew)
                    {
                        command = new KeyStoneCommand(PolyPoints);
                    }
                    else
                    {
                        LeadPoint[] inputPoints =
                        {
                            new LeadPoint(0,                                                0),
                            new LeadPoint(_viewer.Image.ImageWidth,                         0),
                            new LeadPoint(_viewer.Image.ImageWidth, _viewer.Image.ImageHeight),
                            new LeadPoint(0,                        _viewer.Image.ImageHeight),
                        };

                        command = new ManualPerspectiveDeskewCommand(inputPoints, PolyPoints);
                    }

                    try
                    {
                        command.Run(_viewer.Image);
                    }
                    catch (System.Exception ex)
                    {
                        Messager.ShowError(this, ex);
                        return;
                    }

                    //_viewer.Cursor = Cursors.Default;
                    if (command.GetType() == typeof(KeyStoneCommand))
                    {
#if !LEADTOOLS_V20_OR_LATER
                        KeyStoneCommand cmd = command as KeyStoneCommand;
                        if (cmd.TransformedBitmap != null)
                        {
                            _viewer.Image = cmd.TransformedBitmap.Clone();
                        }
#else
                        KeyStoneCommand cmd = command as KeyStoneCommand;
                        if (cmd.TransformedImage != null)
                        {
                            _viewer.Image = cmd.TransformedImage.Clone();
                        }
#endif // #if !LEADTOOLS_V20_OR_LATER
                    }
                    else
                    {
                        // ManualPerspectiveDeskewCommand
                        ManualPerspectiveDeskewCommand cmd = command as ManualPerspectiveDeskewCommand;
                        if (cmd.OutputImage != null)
                        {
                            _viewer.Image = cmd.OutputImage.Clone();
                        }
                    }

                    if (_manualPerspectiveDeskew)
                    {
                        DoAction("ManualPerspectiveCommand", this);
                    }
                    else
                    {
                        DoAction("InversePerspectiveCommand", this);
                    }

                    _viewer.Invalidate();
                    _form.Invalidate();
                    _firstPointSelected = false;
                    _btnReset.Enabled   = true;
                    _btnApply.Enabled   = false;
                }
            }
        }