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());
        }
Exemple #2
0
        /// <summary>
        /// Handles Image Cleaup Actions
        /// </summary>
        /// <param name="e"></param>
        public static void HandleImageCleanupAction(CustomActionEventArgs e)
        {
            if (e.docuVieware.PageCount > 0)
            {
                if (e.docuVieware.GetDocumentType() == DocumentType.DocumentTypeBitmap)
                {
                    int             imageId;
                    GdPictureStatus status = e.docuVieware.GetNativeImage(out imageId);
                    if (status == GdPictureStatus.OK)
                    {
                        status = GdPictureStatus.GenericError;
                        using (GdPictureImaging gdPictImg = new GdPictureImaging())
                        {
                            RotateActionParameters parameters = JsonConvert.DeserializeObject <RotateActionParameters>(e.args.ToString());
                            if (parameters.RegionOfInterest != null && parameters.RegionOfInterest.Width > 0 && parameters.RegionOfInterest.Height > 0)
                            {
                                gdPictImg.SetROI((int)Math.Round(parameters.RegionOfInterest.Left * gdPictImg.GetHorizontalResolution(imageId), 0),
                                                 (int)Math.Round(parameters.RegionOfInterest.Top * gdPictImg.GetVerticalResolution(imageId), 0),
                                                 (int)Math.Round(parameters.RegionOfInterest.Width * gdPictImg.GetHorizontalResolution(imageId), 0),
                                                 (int)Math.Round(parameters.RegionOfInterest.Height * gdPictImg.GetVerticalResolution(imageId), 0));
                            }
                            if (e.actionName != "punchHoleRemoval" || (e.actionName == "punchHoleRemoval" && gdPictImg.GetBitDepth(imageId) == 1))
                            {
                                foreach (var page in parameters.Pages)
                                {
                                    status = gdPictImg.SelectPage(imageId, page);
                                    if (status == GdPictureStatus.OK)
                                    {
                                        switch (e.actionName)
                                        {
                                        case "automaticRemoveBlackBorders":
                                            status = gdPictImg.DeleteBlackBorders(imageId, 10, false);
                                            break;

                                        case "autoDeskew":
                                            status = gdPictImg.AutoDeskew(imageId);
                                            break;

                                        case "punchHoleRemoval":
                                            status = gdPictImg.RemoveHolePunch(imageId, HolePunchMargins.MarginLeft | HolePunchMargins.MarginRight | HolePunchMargins.MarginBottom | HolePunchMargins.MarginTop);
                                            break;

                                        case "despeckle":
                                            status = gdPictImg.FxDespeckle(imageId);
                                            break;
                                        }

                                        if (status != GdPictureStatus.OK)
                                        {
                                            e.message = GetMessage("Error during apply filter: " + status + " on page " + page, DocuViewareMessageIcon.Error);
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        e.message = GetMessage("Error during page selectionr: " + status + "." + page, DocuViewareMessageIcon.Error);
                                        break;
                                    }
                                }   // foreach
                                if (status == GdPictureStatus.OK)
                                {
                                    status    = e.docuVieware.RedrawPages(parameters.Pages);
                                    e.message = status == GdPictureStatus.OK ? new DocuViewareMessage("Filter successfuly applied.", icon: DocuViewareMessageIcon.Ok) : GetMessage("Error during redraw pages : " + status + ".", DocuViewareMessageIcon.Error);
                                }
                            }
                            else
                            {
                                e.message = GetMessage("Your image must be 1 bit-depth to apply this filter!", DocuViewareMessageIcon.Error);
                            }
                        }   // using
                    }
                    else
                    {
                        e.message = GetMessage("Error during get native image : " + status + ".", DocuViewareMessageIcon.Error);
                    }
                }
                else
                {
                    e.message = GetMessage("Only raster formats are supported!", DocuViewareMessageIcon.Error);
                }
            }
            else
            {
                e.message = GetMessage("Please open an image first." + ".", DocuViewareMessageIcon.Error);
            }

            return;
        }