Esempio n. 1
0
        public void _miView_Click(object sender, System.EventArgs e)
        {
            // get the current center in logical units
            ImageViewer viewer = ActiveViewerForm.Viewer; // get the active viewer

            // zoom
            double          scaleFactor = viewer.ScaleFactor;
            ControlSizeMode sizeMode    = ControlSizeMode.None;
            const float     ratio       = 1.2F;

            if (sender == _miViewZoomIn)
            {
                sizeMode     = ControlSizeMode.None;
                scaleFactor *= ratio;
            }
            else if (sender == _miViewZoomOut)
            {
                sizeMode     = ControlSizeMode.None;
                scaleFactor /= ratio;
            }
            else if (sender == _miViewNormal)
            {
                sizeMode    = ControlSizeMode.ActualSize;
                scaleFactor = 1.0;
            }
            else if (sender == _miViewFitToWindow)
            {
                sizeMode    = ControlSizeMode.Fit;
                scaleFactor = 1.0;
            }
            else if (sender == _miViewSnapToImage)
            {
                ViewerForm activeViewer = ActiveViewerForm;
                activeViewer.Snap();
                if (activeViewer.WindowState != FormWindowState.Normal)
                {
                    activeViewer.WindowState = FormWindowState.Normal;
                }
            }

            scaleFactor = Math.Max(_minimumScaleFactor, Math.Min(_maximumScaleFactor, scaleFactor));

            if ((viewer.ScaleFactor != scaleFactor) || (viewer.SizeMode != sizeMode))
            {
                viewer.Zoom(sizeMode, scaleFactor, viewer.DefaultZoomOrigin);
            }
        }
Esempio n. 2
0
        public void UpdateControls( )
        {
            ViewerForm activeForm = ActiveViewerForm;

            EnableAndVisibleMenu(_miFileSaveCurrentAsAbc, activeForm != null);
            EnableAndVisibleMenu(_miFileSaveCurrentAsTIFF, activeForm != null);
            EnableAndVisibleMenu(_miFileSaveAllPagesAsTIFF, activeForm != null);
            EnableAndVisibleMenu(_miFileClose, activeForm != null);
            EnableAndVisibleMenu(_miEdit, activeForm != null);
            EnableAndVisibleMenu(_miView, activeForm != null);
            EnableAndVisibleMenu(_miQuality, activeForm != null);
            EnableAndVisibleMenu(_miWindow, activeForm != null);

            _miFileSaveCurrentAsAbc.Enabled   = _showSave;
            _miFileSaveAllPagesAsTIFF.Enabled = _showSave;
            _miFileSaveCurrentAsTIFF.Enabled  = _showSave;

            if (activeForm != null)
            {
                _miViewNormal.Checked      = activeForm.Viewer.SizeMode != ControlSizeMode.Fit;
                _miViewFitToWindow.Checked = activeForm.Viewer.SizeMode == ControlSizeMode.Fit;
            }
        }
Esempio n. 3
0
        private void _miFileClose_Click(object sender, System.EventArgs e)
        {
            ViewerForm activeViewer = ActiveViewerForm;

            activeViewer.Close();
        }
Esempio n. 4
0
        private void LoadImage(bool loadDefaultImage)
        {
            ImageFileLoader loader       = new ImageFileLoader();
            ViewerForm      activeViewer = ActiveViewerForm;

            try
            {
                ImageInformation info = null;

                if (loadDefaultImage)
                {
                    if (loader.Load(this, DemosGlobal.ImagesFolder + @"\clean.tif", _codecs, 1, 1))
                    {
                        info = new ImageInformation(loader.Image, loader.FileName);
                    }
                }
                else
                {
                    int filesCount = loader.Load(this, _codecs, true);
                    if (filesCount > 0 && loader.Images[0] != null)
                    {
                        info = loader.Images[0];
                    }
                }

                if (info != null)
                {
                    if (info.Image.HasRegion)
                    {
                        info.Image.MakeRegionEmpty();
                    }

                    _fileName  = info.Name;
                    info.Name += " (Original)";

                    if (!_viewerOpened)
                    {
                        NewImage(info, true);
                        _viewerOpened = true;
                    }
                    else
                    {
                        activeViewer.Image = info.Image;
                        activeViewer.Text  = info.Name;
                        if (!((ViewerForm)MdiChildren[0]).OriginalViewer)
                        {
                            MdiChildren[0].Close();
                        }

                        if (MdiChildren.Length > 1)
                        {
                            if (!((ViewerForm)MdiChildren[1]).OriginalViewer)
                            {
                                MdiChildren[1].Close();
                            }
                        }

                        ShowSave = false;
                        if (PreviousCheckQuality != null)
                        {
                            PreviousCheckQuality.Checked = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                UpdateControls();
            }
        }
Esempio n. 5
0
        public void LoadDropFiles(ViewerForm viewer, string[] files)
        {
            try
            {
                if (files != null)
                {
                    for (int nI = 0; nI < files.Length; nI++)
                    {
                        try
                        {
                            RasterImage      image = _codecs.Load(files[nI]);
                            ImageInformation info  = new ImageInformation(image, files[nI]);
                            if (nI == 0 && viewer != null)
                            {
                                viewer.Initialize(info, _paintProperties, false);
                            }
                            else
                            {
                                ViewerForm activeViewer = ActiveViewerForm;

                                _fileName  = info.Name;
                                info.Name += " (Original)";

                                if (!_viewerOpened)
                                {
                                    NewImage(info, true);
                                    _viewerOpened = true;
                                }
                                else
                                {
                                    activeViewer.Image = info.Image;
                                    activeViewer.Text  = info.Name;
                                    if (!((ViewerForm)MdiChildren[0]).OriginalViewer)
                                    {
                                        MdiChildren[0].Close();
                                    }

                                    if (MdiChildren.Length > 1)
                                    {
                                        if (!((ViewerForm)MdiChildren[1]).OriginalViewer)
                                        {
                                            MdiChildren[1].Close();
                                        }
                                    }

                                    ShowSave = false;
                                    if (PreviousCheckQuality != null)
                                    {
                                        PreviousCheckQuality.Checked = false;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Messager.ShowFileOpenError(this, files[nI], ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                UpdateControls();
            }
        }
Esempio n. 6
0
        private void _miQuality_Click(object sender, System.EventArgs e)
        {
            WaitCursor wait = new WaitCursor();

            if (!((ViewerForm)MdiChildren[0]).OriginalViewer)
            {
                MdiChildren[0].Close();
            }

            if (MdiChildren.Length > 1)
            {
                if (!((ViewerForm)MdiChildren[1]).OriginalViewer)
                {
                    MdiChildren[1].Close();
                }
            }

            ((ViewerForm)MdiChildren[0]).Activate();

            if (!Directory.Exists(_saveDirectory))
            {
                Directory.CreateDirectory(_saveDirectory);
            }

            if (File.Exists(_saveFileName))
            {
                File.Delete(_saveFileName);
            }

            if (File.Exists(_saveFileNameG4))
            {
                File.Delete(_saveFileNameG4);
            }

            if (sender == _miQualityLossless)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.Lossless;
                _quality = " (Lossless)";
            }
            else if (sender == _miQualityFastLossless)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.LosslessFast;
                _quality = " (Fast Lossless)";
            }
            else if (sender == _miQualityFastLossy)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.LossyFast;
                _quality = " (Fast Lossy)";
            }
            else if (sender == _miQualityVirtualLossless)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.VirtualLossless;
                _quality = " (Virtual Lossless)";
            }
            else if (sender == _miQualityRemoveBorder)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.RemoveBorder;
                _quality = " (Remove Border)";
            }
            else if (sender == _miQualityEnhanced)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.Enhance;
                _quality = " (Enhance)";
            }
            else if (sender == _miQualityModified1)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.Modified1;
                _quality = " (Modified1)";
            }
            else if (sender == _miQualityFastModified1)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.Modified1Fast;
                _quality = " (Fast Modified1)";
            }
            else if (sender == _miQualityModified2)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.Modified2;
                _quality = " (Modified2)";
            }
            else if (sender == _miQualityFastModified2)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.Modified2Fast;
                _quality = " (Fast Modified2)";
            }
            else if (sender == _miQualityModified3)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.Modified3;
                _quality = " (Modified3)";
            }
            else if (sender == _miQualityFastModified3)
            {
                _codecs.Options.Abc.Save.QualityFactor = CodecsAbcQualityFactor.Modified3Fast;
                _quality = " (Fast Modified3)";
            }

            string tempFileName = _saveFileName;

            if (_previousCheckQuality != null)
            {
                _previousCheckQuality.Checked = false;
            }

            _previousCheckQuality         = (MenuItem)sender;
            _previousCheckQuality.Checked = true;

            try
            {
                ViewerForm activeViewer = ActiveViewerForm;

                _codecs.Save(activeViewer.Image, _saveFileName, RasterImageFormat.Abc, 1);

                tempFileName = _saveFileNameG4;

                _codecs.Save(activeViewer.Image, _saveFileNameG4, RasterImageFormat.CcittGroup4, 1);

                ImageInformation savedImageInformation = new ImageInformation(_codecs.Load(_saveFileName), _saveFileName);

                savedImageInformation.Name += _quality;

                NewImage(savedImageInformation, false);

                LayoutMdi(MdiLayout.TileVertical);
                setCheckWindow(_miWindowTileVertical);

                FileInfo fileInformation = new FileInfo(_saveFileName);

                long previewSize = fileInformation.Length;

                fileInformation = new FileInfo(_saveFileNameG4);

                long previewG4Size = fileInformation.Length;

                int improvement = (int)(((double)previewG4Size / previewSize) * 10000.0 - 10000);

                Messager.ShowInformation(this, string.Format("CCITT G4: {0:#,##0}  bytes\nLEAD ABC: {1:#,##0} bytes\n\n{2:0.00}% Reduction", previewG4Size, previewSize, improvement / 100.0));
                _showSave = true;
            }
            catch (Exception ex)
            {
                Messager.ShowFileSaveError(this, tempFileName, ex);
            }
            wait.Dispose();
            UpdateControls();
        }