コード例 #1
0
        public string DetectMICRLine(string ImageFile)
        {
            string errorCode;

            // CloseNativeImage();
            _imageId = _gdPictureImaging.CreateGdPictureImageFromFile(ImageFile);
            _gdPictureImaging.AutoDeskew(_imageId);
            // System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            // sw.Start();
            int           Length = 36;
            StringBuilder result = new StringBuilder(_gdPictureImaging.MICRDoMICR(_imageId, MICRFont.MICRFontE13B,
                                                                                  MICRContext.MICRContextLineFinding, "0123456789ABCD", Length));

            result = result.Replace(System.Convert.ToString('\0'), "?");
            // sw.Stop();
            GdPictureStatus status = _gdPictureImaging.GetStat();

            if (status == GdPictureStatus.OK)
            {
                result.ToString();
            }
            else
            {
                errorCode = status.ToString();
                return(errorCode);
            }
            _gdPictureImaging.Dispose();

            return(result.ToString());
        }
コード例 #2
0
 private void ThrowIfFailed(GdPictureStatus status, string step)
 {
     if (status != GdPictureStatus.OK)
     {
         string message = $"{step} failed: {status.ToString()}";
         logger.LogError(message);
         throw new Exception(message);
     }
 }
コード例 #3
0
        private static void ProcessMovedFileWithGdPicture(string filePath, string ocrDirectory, string completedDirectory)
        {
            var fileName = Path.GetFileName(filePath);
            //We assume that GdPicture has been correctly installed and unlocked.
            GdPicturePDF oGdPicturePDF = new GdPicturePDF();
            //Loading an input document.
            GdPictureStatus status = oGdPicturePDF.LoadFromFile(filePath, false);

            //Checking if loading has been successful.
            if (status == GdPictureStatus.OK)
            {
                int pageCount = oGdPicturePDF.GetPageCount();
                //Loop through pages.
                for (int i = 1; i <= pageCount; i++)
                {
                    //Selecting a page.
                    oGdPicturePDF.SelectPage(i);
                    if (oGdPicturePDF.OcrPage("eng", ocrDirectory, "", 200.0F) != GdPictureStatus.OK)
                    {
                        //Console.WriteLine("OCR Pages Example - Error occurred on the page " + i.ToString() + ". Error: " + oGdPicturePDF.GetStat().ToString());
                    }
                }
                //Saving to a different file.
                var completedFilePath = Path.Combine(
                    completedDirectory,
                    fileName
                    );
                status = oGdPicturePDF.SaveToFile(completedFilePath, true);
                if (status == GdPictureStatus.OK)
                {
                    Console.WriteLine("OCR Pages Example - Done! " + fileName);
                }
                else
                {
                    Console.WriteLine("OCR Pages Example - " + "The document can't be saved." + status.ToString() + " " + fileName);
                }
                //Closing and releasing resources.
                oGdPicturePDF.CloseDocument();
            }
            else
            {
                Console.WriteLine("OCR Pages Example - " + "The document can't be opened." + status.ToString() + " " + fileName);
            }
            oGdPicturePDF.Dispose();
        }