Example #1
0
        private void ApplyFilter()
        {
            using (WaitCursor wait = new WaitCursor())
            {
                if (_unWarpPoints.Count > 4 && _firstPointSelected)
                {
                    _applied = true;
                    LeadPoint[] UnWarpPoints = new LeadPoint[8];
                    for (int i = 0; i < 8; i++)
                    {
                        UnWarpPoints[i].X = _unWarpPoints[i].X;
                        UnWarpPoints[i].Y = _unWarpPoints[i].Y;
                    }

                    _viewer.Image.MakeRegionEmpty();

                    UnWarpCommand command = new UnWarpCommand(UnWarpPoints);

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

                    if (command.OutputImage != null)
                    {
                        _viewer.Image = command.OutputImage.Clone();
                    }

                    DoAction("UnWarpCommand", this);

                    _viewer.Invalidate();
                    _form.Invalidate();
                    _firstPointSelected = false;
                    _btnReset.Enabled   = true;
                    _btnApply.Enabled   = false;
                }
            }
        }
Example #2
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;
                }
            }
        }