예제 #1
0
        // This method copies the selected file into a temp directory for OCR processing.
        // The file must be coppied because the Translate method must be supplied a directory
        // containing all of the images to process.
        private void OnMenuFileOpenClick(object sender, EventArgs e)
        {
            // try to locate images folder
            var path = Application.ExecutablePath;
            // we assume we are running under the DotImage install folder
            var imagesFolder = Path.GetDirectoryName(path);

            while (path != null)
            {
                path = Path.GetDirectoryName(path);
                var folderName = Path.GetFileName(path);
                if (folderName == null || !folderName.Contains("DotImage "))
                {
                    continue;
                }
                imagesFolder = Path.Combine(path, "Images\\Documents");
                break;
            }

            //use this folder as starting point
            _openFileDialog.InitialDirectory = imagesFolder;
            _openFileDialog.Filter           = WinDemoHelperMethods.CreateDialogFilter(true);

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

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

            try
            {
                File.Delete(TempFile);
                File.Copy(_openFileDialog.FileName, TempFile, true);
            }
            catch (Exception ex)
            {
                _fileLoaded = false;
                InfoBox(ex.Message);
                return;
            }

            // display the file.
            try
            {
                _workspaceViewer.Open(TempFile);
                _fileLoaded = true;
            }
            catch (Exception)
            {
                _fileLoaded = false;
                MessageBox.Show("Unable to open requested image... Unsupported Image Type.");
            }
        }
예제 #2
0
 static MainForm()
 {
     WinDemoHelperMethods.PopulateDecoders(RegisteredDecoders.Decoders);
 }