private int[] splitImage(FREngine.IFRDocument frDoc, FREngine.IPageProcessingParams ppp, ProcessingSettings settings) { FREngine.PageSplittingParams pageSplittingParams = engine.CreatePageSplittingParams(); pageSplittingParams.SplitType = FREngine.PageSplitTypeEnum.PST_None; if (settings.SplitPages) { pageSplittingParams.SplitType = FREngine.PageSplitTypeEnum.PST_DoublePageSplit; } else if (settings.SplitBusinessCards) { pageSplittingParams.SplitType = FREngine.PageSplitTypeEnum.PST_BusinessCardSplit; } else { int[] emptyPageIndices = new int[1]; emptyPageIndices[0] = 0; return(emptyPageIndices); } if (settings.CorrectOrientationMode != ProcessingSettings.OrientationCorrectionMode.None) { ppp.PagePreprocessingParams.CorrectOrientation = true; } engine.MultiProcessingParams.MultiProcessingMode = FREngine.MultiProcessingModeEnum.MPM_Sequential; FREngine.SplitRegions splitRegions = frDoc.SplitPages(null, pageSplittingParams, ppp.ObjectsExtractionParams); engine.MultiProcessingParams.MultiProcessingMode = FREngine.MultiProcessingModeEnum.MPM_Auto; int[] sourcePageIndices = new int[frDoc.Pages.Count]; for (int pageIndex = 0; pageIndex < sourcePageIndices.Length; pageIndex++) { sourcePageIndices[pageIndex] = -1; } foreach (FREngine.SplitRegion item in splitRegions) { FREngine.IFRPage frPage = frDoc.Pages[item.CurrentPageIndex]; sourcePageIndices[item.CurrentPageIndex] = item.SourcePageIndex; if (settings.CropImage) { frPage.ImageDocument.CropImage(); } if (settings.CorrectDistortions) { frPage.CorrectGeometricalDistortions(ppp.ObjectsExtractionParams); } if (settings.DeskewImage) { frPage.ImageDocument.CorrectSkew(correctSkewFlags); } frPage.Flush(true); } for (int pageIndex = 0; pageIndex < sourcePageIndices.Length; pageIndex++) { if (sourcePageIndices[pageIndex] == -1) { sourcePageIndices[pageIndex] = pageIndex == 0 ? 0 : sourcePageIndices[pageIndex - 1] + 1; } } return(sourcePageIndices); }
private void applyGeometricalTransformations(FREngine.IFRPage page, FREngine.IPageProcessingParams ppp, ProcessingSettings settings, FREngine.RotationTypeEnum detectedRotation) { checkProcessingSettingsForImage(page.ImageDocument.ImageColorType, ref settings); if (settings.CropImage) { page.ImageDocument.CropImage(); } if (settings.EnhanceLocalContrast) { page.ImageDocument.EnhanceLocalContrast(); } if (settings.CorrectOrientationMode != ProcessingSettings.OrientationCorrectionMode.None && detectedRotation != FREngine.RotationTypeEnum.RT_NoRotation) { FREngine.RotationTypeEnum rotation = FREngine.RotationTypeEnum.RT_NoRotation; bool mirror = false; if (detectedRotation != FREngine.RotationTypeEnum.RT_UnknownRotation) { switch (detectedRotation) { case FREngine.RotationTypeEnum.RT_Clockwise: rotation = FREngine.RotationTypeEnum.RT_Counterclockwise; break; case FREngine.RotationTypeEnum.RT_Upsidedown: rotation = FREngine.RotationTypeEnum.RT_Upsidedown; break; case FREngine.RotationTypeEnum.RT_Counterclockwise: rotation = FREngine.RotationTypeEnum.RT_Clockwise; break; default: break; } } else { switch (settings.CorrectOrientationMode) { case ProcessingSettings.OrientationCorrectionMode.Rotate90CW: rotation = FREngine.RotationTypeEnum.RT_Clockwise; break; case ProcessingSettings.OrientationCorrectionMode.Rotate180UpsideDown: rotation = FREngine.RotationTypeEnum.RT_Upsidedown; break; case ProcessingSettings.OrientationCorrectionMode.Rotate90CCW: rotation = FREngine.RotationTypeEnum.RT_Counterclockwise; break; case ProcessingSettings.OrientationCorrectionMode.MirrorHorizontally: mirror = true; break; default: break; } } page.ImageDocument.Transform(rotation, mirror, false); } if (settings.InvertImage) { page.ImageDocument.Transform(FREngine.RotationTypeEnum.RT_NoRotation, false, true); } if (settings.CorrectDistortions) { page.CorrectGeometricalDistortions(ppp.ObjectsExtractionParams); } if (settings.DeskewImage) { page.ImageDocument.CorrectSkew(correctSkewFlags); } }