public void ConvertToGrayScale(string sourceFile, string targetFile)
        {
            MultiFramedImageEncoder encoder = new TiffEncoder();

            using (ImageSource src = new FileSystemImageSource(sourceFile, true))
            {
                ImageCollection images = new ImageCollection();

                while (src.HasMoreImages())
                {
                    AtalaImage img = src.AcquireNext();

                    img = img.GetChangedPixelFormat(PixelFormat.Pixel8bppGrayscale);
                    images.Add(img);
                    //img.Dispose();
                }

                using (Stream s = File.Create(targetFile))
                {
                    encoder.Save(s, images, null);
                }
            }
        }
Ejemplo n.º 2
0
        //  This method does the actual translation into text.
        private void DoTranslation()
        {
            if (!_fileLoaded)
            {
                MessageBox.Show("No file loaded... Please open a file and try again.");
            }
            else
            {
                try
                {
                    _textBox.Clear();

                    // choose output file location, either a temp directory, or a user selected spot.
                    if (_saveToFile)
                    {
                        _outputFile = GetSaveFileName();
                    }
                    if (_outputFile == null)
                    {
                        return;
                    }

                    // delete the output file if one already exists
                    if (File.Exists(_outputFile))
                    {
                        File.Delete(_outputFile);
                    }

                    // OK, we're committed, put up the wait cursor
                    UseWaitCursor  = true;
                    Cursor.Current = Cursors.WaitCursor;

                    // this is how the image should be passed to the translator
                    var imageSource = new FileSystemImageSource(TempDir, true);

                    _progressBar.Value = 0;

                    // do the actual translation here.  The text is saved as a file in _outputFile.
                    _engine.Translate(imageSource, _selectedMimeType, _outputFile);

                    if (!_saveToFile)
                    {
                        // Load the text back into the text box for display.
                        var input   = new StreamReader(_outputFile);
                        var oneLine = input.ReadLine();
                        while (oneLine != null)
                        {
                            _textBox.AppendText(oneLine);
                            oneLine = input.ReadLine();
                        }
                        input.Close();
                    }
                    else
                    {
                        Process.Start(_outputFile);
                    }
                }
                catch (Exception ex)
                {
                    // if it's a license exception, it's probably because of pdfTranslator
                    if ((ex is AtalasoftLicenseException) && (_selectedMimeType == "application/pdf"))
                    {
                        LicenseCheckFailure(
                            "To generate PDF output, an Atalasoft PDF Translator license is required.",
                            ex.Message);
                    }
                    else
                    {
                        InfoBox(ex.ToString());
                    }
                }
                finally
                {
                    UseWaitCursor = false;
                    _progressBar.Hide();
                }
            }
        }