Exemple #1
0
        internal string repairPage(string fileName, int page, string fileOut, EFileFormat format)
        {
            CiRepair repair = null;

            try
            {
                CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
                repair = ci.CreateRepair();
                repair.Image.Open(fileName, page);
                //  Demonstrates basic
                string s = "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
                repair.AutoDeskew(); s             = s + "AutoDeskew" + Environment.NewLine;
                repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
                //  Save results
                SavePage(ref s, repair.Image, fileOut, format);
                s = s + Environment.NewLine + "--------------" + Environment.NewLine;
                return(s);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                if (repair != null)
                {
                    repair.Image.Close();                  // ClearImage V9 and later.  Immediately free memory
                }
            }
        }
Exemple #2
0
        internal string repairStream(string fileName, string fileOut, EFileFormat format)
        {
            CiRepair repair = null;

            try
            {
                CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
                repair = ci.CreateRepair();
                using (MemoryStream ms = Utility.FileToStream(fileName))
                {
                    //  Read images from file
                    string s = "";
                    // Disable zone
                    int page = 1;
                    repair.Image.Open(ms, 1);
                    int cnt   = 0;
                    int pages = repair.Image.PageCount;
                    while (repair.Image.IsValid)
                    {
                        s = s + "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
                        repair.AutoDeskew(); s             = s + "AutoDeskew" + Environment.NewLine;
                        repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
#if false  // to write to multipage file
                        SavePage(ref s, repair.Image, fileOut, format);
#else      // save single page to file
                        MemoryStream msOut = repair.Image.SaveToStream(format);
                        if (msOut != null)
                        {
                            string pageOut =
                                Path.GetDirectoryName(fileOut) + @"\" +
                                Path.GetFileNameWithoutExtension(fileOut) +
                                ".page_" + page.ToString() +
                                Path.GetExtension(fileOut);
                            Utility.StreamToFile(msOut, pageOut);
                        }
#endif
                        page++;
                        if (page > pages)
                        {
                            break;
                        }
                        repair.Image.OpenPage(page);
                    }
                    s = s + Environment.NewLine;
                    return(s);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                if (repair != null)
                {
                    repair.Image.Close();                  // ClearImage V9 and later.  Immediately free memory
                }
            }
        }
Exemple #3
0
        internal string repairFile(string fileName, string fileOut, EFileFormat format)
        {
            CiRepair repair = null;

            try
            {
                CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer();
                repair = ci.CreateRepair();
                //  Read images from file
                string s = "";
                // Disable zone
                int page = 1;
                repair.Image.Open(fileName, 1);
                int cnt   = 0;
                int pages = repair.Image.PageCount;
                while (repair.Image.IsValid)
                {
                    s = s + "File:" + fileName + "  Page:" + page.ToString() + Environment.NewLine;
                    repair.AutoDeskew(); s             = s + "AutoDeskew" + Environment.NewLine;
                    repair.AutoCrop(50, 50, 50, 50); s = s + "AutoCrop (margins 50pix)" + Environment.NewLine;
                    SavePage(ref s, repair.Image, fileOut, format);
                    page++;
                    if (page > pages)
                    {
                        break;
                    }
                    repair.Image.Open(fileName, page);
                }
                s = s + Environment.NewLine;
                return(s);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                if (repair != null)
                {
                    repair.Image.Close();                  // ClearImage V9 and later.  Immediately free memory
                }
            }
        }