Exemplo n.º 1
0
        /*
         * Loads an image into the viewer
         */
        private void btnSelectImage_Click(object sender, EventArgs e)
        {
            try
            {
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    ImageFileLoader loader = new ImageFileLoader();

                    loader.ShowLoadPagesDialog = true;

                    if (loader.Load(this, codecs, true) > 0)
                    {
                        rasterImageViewer.Image = loader.Image.Clone();
                        ((MainForm)Parent.Parent).btnNext.Enabled = true;
                    }

                    // Disable the next button if the user doesn't have an image and an item selected
                    ((MainForm)Parent.Parent).btnNext.Enabled = ((rasterImageViewer.Image != null) && (_globals.m_TreeResult.SelectedNode != null));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 2
0
        private void _fileOpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Open a document from disk

            // Show the LEADTOOLS common dialog
            ImageFileLoader loader = new ImageFileLoader();

            loader.LoadOnlyOnePage       = true;
            loader.ShowLoadPagesDialog   = false;
            loader.OpenDialogInitialPath = _openInitialPath;

            try
            {
                // Insert the pages loader into the document
                if (loader.Load(this, _rasterCodecs, false) > 0)
                {
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);
                    OpenDocument(loader.FileName);
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
Exemplo n.º 3
0
        private void LoadImage(bool loadDefaultImage)
        {
            RasterOpenDialogLoadFormat[] loaderFilters = new RasterOpenDialogLoadFormat[3];
            loaderFilters[0] = new RasterOpenDialogLoadFormat("Bitmap Files (*.dib;*.bmp)", "*.dib;*.bmp");
            loaderFilters[1] = new RasterOpenDialogLoadFormat("TIFF Files (*.tif)", "*.tif");
            loaderFilters[2] = new RasterOpenDialogLoadFormat("All Files (*.tif, *.bmp)", "*.tif;*.bmp");

            ImageFileLoader loader = new ImageFileLoader();

            loader.OpenDialogInitialPath = _openInitialPath;
            loader.Filters = loaderFilters;

            bool bLoaded = false;

            try
            {
                if (loadDefaultImage)
                {
                    bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ET\dst_rgb_image.tif", _codecs, 1, 1);
                }
                else
                {
                    bLoaded = loader.Load(this, _codecs, true) > 0;
                }

                if (bLoaded)
                {
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);
                    // Resize the image so each dimension becomes a multiple of 4. This is done because it's required by some color spaces
                    int width  = loader.Image.Width;
                    int height = loader.Image.Height;

                    width  += (width % 4 == 0) ? 0 : (4 - (width % 4));
                    height += (height % 4 == 0) ? 0 : (4 - (height % 4));

                    // If the width and the height were the same, the SizeCommand will return immediately.
                    SizeCommand sizeCommand = new SizeCommand(width, height, RasterSizeFlags.None);
                    sizeCommand.Run(loader.Image);

                    CodecsImageInfo info = _codecs.GetInformation(loader.FileName, false, 1);
                    if (info.BitsPerPixel == 24)
                    {
                        _viewer.Image = loader.Image;
                        Text          = "LEADTOOLS for .NET C# Color Conversion Demo";
                    }
                    else
                    {
                        Messager.ShowError(this, "Format not supported\nthis demo supports simple TIFF - (RGB24, CMYK, YCC and LAB) and BMP - (RGB24)");
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                UpdateMyControls();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Open new image
        /// </summary>
        private void _miFileOpen_Click(object sender, System.EventArgs e)
        {
            try
            {
                ImageFileLoader loader = new ImageFileLoader();

                loader.OpenDialogInitialPath = _openInitialPath;
                loader.ShowLoadPagesDialog   = true;
                if (loader.Load(this, _codecs, true) > 0)
                {
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);
                    // update the caption
                    Text = string.Format("{0} - {1}", loader.FileName, Messager.Caption);

                    // set the new image in the viewer
                    _viewer.Image = loader.Image;
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                UpdateMyControls();
            }
        }
Exemplo n.º 5
0
        private void _btnBrowseImageFile_Click(object sender, EventArgs e)
        {
            ImageFileLoader loader = new ImageFileLoader();

            loader.OpenDialogInitialPath = _openInitialPath;
            try
            {
                if (loader.Load(this, _codecs, false) > 0)
                {
                    if (LoadImage(loader.FileName))
                    {
                        _openInitialPath       = Path.GetDirectoryName(loader.FileName);
                        _lblImageFileName.Text = loader.FileName;
                        MyItemData itemData = (MyItemData)_cmbOcrModules.Items[_cmbOcrModules.SelectedIndex];
                        itemData.ImageFileName = loader.FileName;
                        this._cmbOcrModules.SelectedIndexChanged          -= new System.EventHandler(this._cmbOcrModules_SelectedIndexChanged);
                        _cmbOcrModules.Items[_cmbOcrModules.SelectedIndex] = itemData;
                        this._cmbOcrModules.SelectedIndexChanged          += new System.EventHandler(this._cmbOcrModules_SelectedIndexChanged);
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowFileOpenError(this, loader.FileName, ex);
            }
        }
Exemplo n.º 6
0
        private void LoadImage(bool loadDefaultImage)
        {
            try
            {
                ImageFileLoader loader  = new ImageFileLoader();
                bool            bLoaded = false;

                if (loadDefaultImage)
                {
                    bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\image1.j2k", _codecs, 1, 1);
                }
                else
                {
                    ImageFileLoader.FilterIndex = 5;
                    bLoaded = loader.Load(this, _codecs, true) > 0;
                }

                if (bLoaded)
                {
                    // Load and set the new image in the viewer
                    _viewer.Image = loader.Image;

                    // Get the information about the image
                    CodecsImageInfo imageInformation = _codecs.GetInformation(loader.FileName, false);
                    switch (imageInformation.Format)
                    {
                    case RasterImageFormat.J2k:
                    case RasterImageFormat.Jp2:
                    case RasterImageFormat.Cmw:
                    {
                        this.Text = String.Format("LEADTOOLS for .NET C# JPEG 2000 Demo {0} X {1}", _viewer.Image.Width, _viewer.Image.Height);
                        break;
                    }

                    default:
                    {
                        this.Text = string.Format("{0} - {1}", loader.FileName, Messager.Caption);
                        break;
                    }
                    }

                    _fileName = loader.FileName;

                    _originalWidth  = imageInformation.Width;
                    _originalHeight = imageInformation.Height;

                    _viewer.Invalidate(true);
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                UpdateMyControls();
            }
        }
Exemplo n.º 7
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ImageFileLoader loader = new ImageFileLoader();

            loader.ShowLoadPagesDialog = true;
            loader.MultiSelect         = false;
            loader.ShowPdfOptions      = true;
            loader.ShowLoadPagesDialog = false;
            if (loader.Load(this, rasterCodecs, true) > 0)
            {
                OpenImage(loader.FileName);
            }
        }
Exemplo n.º 8
0
        public static Sprite Create(string texturePath)
        {
            Texture2D texture = CreateTexture2D(ImageFileLoader.LoadAsBinary(texturePath));

            Sprite sprite = (texture == null) ?
                            DefaultSprite :
                            Sprite.Create(
                texture,
                new Rect(0f, 0f, texture.width, texture.height),
                new Vector2(0.5f, 0.5f));

            return(sprite);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Load a new image
        /// </summary>
        private void _miFileOpen_Click(object sender, System.EventArgs e)
        {
            try
            {
                // load the image
                ImageFileLoader loader = new ImageFileLoader();
                loader.OpenDialogInitialPath = _openInitialPath;
                loader.LoadOnlyOnePage       = true;
                _isLoading  = true;
                _cancelLoad = false;
                UpdateMyControls();
                if (loader.Load(this, _codecs, false) > 0)
                {
                    _viewer.Image    = null;
                    Text             = Messager.Caption;
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);

                    _codecs.LoadImage += new EventHandler <CodecsLoadImageEventArgs>(_codecs_LoadImage);

                    try
                    {
                        _viewer.Image = _codecs.Load(loader.FileName, 0, CodecsLoadByteOrder.BgrOrGray, loader.FirstPage, loader.LastPage);

                        // update the caption
                        Text = string.Format("{0} - {1}", loader.FileName, Messager.Caption);
                    }
                    catch (Exception ex)
                    {
                        Messager.ShowError(this, ex);
                    }
                    finally
                    {
                        _codecs.LoadImage -= new EventHandler <CodecsLoadImageEventArgs>(_codecs_LoadImage);
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                _isLoading  = false;
                _cancelLoad = false;
                UpdateMyControls();
            }
        }
Exemplo n.º 10
0
        private List <ImageInformation> LoadImages(bool bMultiSelect)
        {
            try
            {
                bool bSetInitialPath = false;
                if (_loader == null)
                {
                    bSetInitialPath = true;
                }

                _loader = new ImageFileLoader();
                _loader.ShowLoadPagesDialog = false;

                if (bSetInitialPath)
                {
                    if (Directory.Exists(DemosGlobal.ImagesFolder))
                    {
                        _loader.OpenDialogInitialPath = DemosGlobal.ImagesFolder;
                    }
                }

                _loader.MultiSelect = bMultiSelect;
                RasterOpenDialogLoadFormat[] filters = { new RasterOpenDialogLoadFormat("Tiff", "*.tif;*.tiff") };
                _loader.Filters = filters;
                _loader.Images.Clear();
                int filesCount = _loader.Load(this, _codecs, true);
                if (filesCount > 0)
                {
                    for (int i = 0; i < _loader.Images.Count; i++)
                    {
                        if (_loader.Images[i].Image != null)
                        {
                            _loader.Images[i].Image.Dispose();
                        }
                    }

                    return(_loader.Images);
                }
            }
            catch (Exception ex)
            {
                Messager.ShowFileOpenError(this, _loader.FileName, ex);
            }

            return(null);
        }
Exemplo n.º 11
0
        private void LoadImage(bool loadDefaultImage, bool addingPage)
        {
            ImageFileLoader loader = new ImageFileLoader();

            loader.OpenDialogInitialPath = _openInitialPath;


            try
            {
                loader.ShowLoadPagesDialog = true;

                if (loadDefaultImage)
                {
                    string imagePath = System.IO.Path.Combine(DemosGlobal.ImagesFolder, "image1.gif");
                    if (!System.IO.File.Exists(imagePath))
                    {
                        imagePath = System.IO.Path.Combine(Application.StartupPath, "image1.gif");
                    }
                    if (loader.Load(this, imagePath, _codecs, 1, -1))
                    {
                        NewImage(new ImageInformation(loader.Image, loader.FileName));
                    }
                }
                else
                {
                    if (loader.Load(this, _codecs, true) > 0)
                    {
                        _openInitialPath = Path.GetDirectoryName(loader.FileName);
                        if (addingPage)
                        {
                            ActiveViewerForm.Image.AddPages(loader.Image, 1, loader.Image.PageCount);
                        }
                        else
                        {
                            NewImage(new ImageInformation(loader.Image, loader.FileName));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowFileOpenError(this, loader.FileName, ex);
            }
        }
Exemplo n.º 12
0
        private void _miFileOpen_Click(object sender, System.EventArgs e)
        {
            ImageFileLoader loader = new ImageFileLoader();

            loader.OpenDialogInitialPath = _openInitialPath;

            try
            {
                loader.LoadOnlyOnePage = true;
                if (loader.Load(this, _codecs, true) > 0)
                {
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);
                    CreateChildForm(loader.Image, loader.FileName);
                }
            }
            catch (Exception ex)
            {
                Messager.ShowFileOpenError(this, loader.FileName, ex);
            }
        }
Exemplo n.º 13
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         ImageFileLoader loader = new ImageFileLoader();
         loader.ShowLoadPagesDialog = true;
         loader.MultiSelect         = false;
         loader.ShowPdfOptions      = true;
         loader.ShowLoadPagesDialog = false;
         if (loader.Load(this, rasterCodecs, true) > 0)
         {
             OpenImage(loader.Image);
         }
     }
     catch (Exception exp)
     {
         EnableControls(true);
         Messager.ShowError(this, exp);
     }
 }
Exemplo n.º 14
0
        private void OpenImageFile()
        {
            // Open an image file from disk and put it in the viewer
            ImageFileLoader loader = new ImageFileLoader();

            loader.OpenDialogInitialPath = _openInitialPath;

            try
            {
                loader.ShowLoadPagesDialog = true;

                if (loader.Load(this, _codecs, true) > 0)
                {
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);
                    SetViewerImage(loader.FileName, loader.Image, Path.GetFileName(loader.FileName));
                }
            }
            catch (Exception ex)
            {
                Messager.ShowFileOpenError(this, loader.FileName, ex);
            }
        }
Exemplo n.º 15
0
        private ImageInformation LoadImage()
        {
            ImageFileLoader loader = new ImageFileLoader();

            loader.OpenDialogInitialPath = _openInitialPath;

            try
            {
                loader.LoadOnlyOnePage     = true;
                loader.ShowLoadPagesDialog = false;
                if (loader.Load(this, _codecs, true) > 0)
                {
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);
                    return(new ImageInformation(loader.Image, loader.FileName));
                }
            }
            catch (Exception ex)
            {
                Messager.ShowFileOpenError(this, loader.FileName, ex);
            }

            return(null);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Underlay an Image
 /// </summary>
 private void _miBasicFeaturesUnderlay_Click(object sender, EventArgs e)
 {
     try
     {
         ImageFileLoader loader = new ImageFileLoader();
         if (loader.Load(this, _codecs, true) <= 0)
         {
             return;
         }
         using (UnderlayDialog dlg = new UnderlayDialog())
         {
             if (dlg.ShowDialog(this) != DialogResult.OK)
             {
                 return;
             }
             using (WaitCursor wait = new WaitCursor())
                 _viewer.Image.Underlay(loader.Image, dlg.Flags);
         }
     }
     catch (Exception ex)
     {
         Messager.ShowError(this, ex);
     }
 }
Exemplo n.º 17
0
        private void LoadImage(bool loadDefaultImage)
        {
            ImageFileLoader loader = new ImageFileLoader();
            bool            bLoaded;

            loader.OpenDialogInitialPath = _openInitialPath;

            try
            {
                loader.LoadOnlyOnePage = true;

                if (loadDefaultImage)
                {
                    if (_ocrEngineType == OcrEngineType.OmniPageArabic)
                    {
                        bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ArabicSample.tif", _codecs, 1, -1);
                    }
                    else
                    {
                        bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ocr1.tif", _codecs, 1, -1);
                    }
                }
                else
                {
                    bLoaded = loader.Load(this, _codecs, true) > 0;
                }

                if (bLoaded)
                {
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);

                    RasterImage image = loader.Image;
                    if (image.XResolution < 150)
                    {
                        image.XResolution = 150;
                    }

                    if (image.YResolution < 150)
                    {
                        image.YResolution = 150;
                    }

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

                    _viewer.Image = image;

                    if (_ocrEngine.IsStarted)
                    {
                        _ocrPage = _ocrEngine.CreatePage(image, OcrImageSharingMode.None);
                    }

                    _currentHighlightRect    = LeadRect.Empty;
                    _recognitionResults.Text = "";

                    _tsMainZoomComboBox_SelectedIndexChanged(_tsMainZoomComboBox, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                Messager.ShowFileOpenError(this, loader.FileName, ex);
            }
            finally
            {
                _viewer.Invalidate();
            }
        }
        private void LoadImage(bool loadDefaultImage)
        {
            ImageFileLoader loader = new ImageFileLoader();
             bool bLoaded;

             loader.OpenDialogInitialPath = _openInitialPath;

             try
             {
            loader.LoadOnlyOnePage = true;

            if (loadDefaultImage)
            {
               if (_ocrEngineType == OcrEngineType.Arabic)
                  bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ArabicSample.tif", _codecs, 1, -1);
               else
                  bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ocr1.tif", _codecs, 1, -1);
            }
            else
               bLoaded = loader.Load(this, _codecs, true) > 0;

            if (bLoaded)
            {
               _openInitialPath = Path.GetDirectoryName(loader.FileName);

               RasterImage image = loader.Image;
               if (image.XResolution < 150)
                  image.XResolution = 150;

               if (image.YResolution < 150)
                  image.YResolution = 150;

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

               _viewer.Image = image;

               if (_ocrEngine.IsStarted)
                  _ocrPage = _ocrEngine.CreatePage(image, OcrImageSharingMode.None);

               _currentHighlightRect = LeadRect.Empty;
               _recognitionResults.Text = "";

               _tsMainZoomComboBox_SelectedIndexChanged(_tsMainZoomComboBox, new EventArgs());
            }
             }
             catch (Exception ex)
             {
            Messager.ShowFileOpenError(this, loader.FileName, ex);
             }
             finally
             {
            _viewer.Invalidate();
             }
        }
Exemplo n.º 19
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();
            }
        }