Sets the overlay image of this IOcrPage
void SetOverlayImage(Leadtools.RasterImage image)
Sub SetOverlayImage( _ByVal image As Leadtools.RasterImage _)
void SetOverlayImage(Leadtools.RasterImage image)
- (void)setOverlayImage:(LTRasterImage *)image error:(NSError **)error public void setOverlayImage(RasterImage value) function Leadtools.Forms.Ocr.IOcrPage.SetOverlayImage(image)
void SetOverlayImage(Leadtools.RasterImage^ image)
image
The overlay image. This value can be null.
The overlay image of an IOcrPage will be used when the image is saved by an IOcrDocument in the following situations:
If the page contains a graphics zone (OcrZoneType.Graphics. The document will get the image to store in the document from the overlay image.
If the output format supports the "Image over text" feature. Such as PDF with Image/Text option. The document will get the image to store in the document from the overlay image.
By the default, the overlay image is the original image used to create the page. It is the same value obtained by calling GetRasterImage with OcrPageType.Original.
In some situation, the user might want use a different image as the overlay. For example, a smaller version is passed to the OCR engine to conserve memory while the original version will only be used on save purposes in a PDF with image/text option. You can call SetOverlayImage before saving the document (memory-based) or adding the page to the document (file-based) and the engine will use this new image as the overlay value. If auto-preprocessing was performed on the page through AutoPreprocess, then the same values might need to be applied to the overlay as well. Use GetPreprocessValues to get the accumulative values of any inversion, rotation or deskewing applied by the pre-processor.
To clear the temporarily overlay image, call SetOverlayImage with a null value.
To get the overlay image at any time, call GetOverlayImage. Note that this property will the same image reference passed to the last SetOverlayImage call. It will not return the original image.
The overlay image is not disposed by this IOcrPage.
using Leadtools;using Leadtools.Codecs;using Leadtools.Forms.Ocr;using Leadtools.Forms;using Leadtools.Forms.DocumentWriters;using Leadtools.WinForms;using Leadtools.Drawing;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;public static void SetOverlayImageExample(){var originalFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");var imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1_Deskewed.tif");var outFileName = Path.Combine(LEAD_VARS.ImagesDir, "result.pdf");using (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)){ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);// Mimimc having an image that is deskewedusing (var rasterImage = ocrEngine.RasterCodecsInstance.Load(originalFileName, 1)){// Rotate the image by 5 degrees to mimic deskewvar rotateCommand = new RotateCommand(5 * 100, RotateCommandFlags.None, RasterColor.FromKnownColor(RasterKnownColor.White));rotateCommand.Run(rasterImage);ocrEngine.RasterCodecsInstance.Save(rasterImage, imageFileName, RasterImageFormat.CcittGroup4, 1);}// Now we are ready. We will create a PDF for the result with image over text overlay. And we will intercept creating// the overlay and use the original image instead// Use PDF with image/text optionvar pdfOptions = ocrEngine.DocumentWriterInstance.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;pdfOptions.ImageOverText = true;ocrEngine.DocumentWriterInstance.SetOptions(DocumentFormat.Pdf, pdfOptions);// Create an OCR AutoRecognize jobvar jobData = new OcrAutoRecognizeJobData{ImageFileName = imageFileName,FirstPageNumber = 1,LastPageNumber = -1,DocumentFileName = outFileName,Format = DocumentFormat.Pdf};var autoRecognizeManager = ocrEngine.AutoRecognizeManager;var job = autoRecognizeManager.CreateJob(jobData);// Setup pre-processing commandsautoRecognizeManager.EnableTrace = true;autoRecognizeManager.PreprocessPageCommands.Clear();autoRecognizeManager.PreprocessPageCommands.Add(OcrAutoPreprocessPageCommand.All);OcrAutoRecognizeManagerJobStatus status;EventHandler<OcrAutoRecognizeJobOperationEventArgs> jobOperation = (sender, e) =>{if (e.Operation == OcrAutoRecognizeManagerJobOperation.SavePage){if (!e.PostOperation){// Get the pre-processing values for the pagevar values = e.Page.GetPreprocessValues();// Show the status of itConsole.WriteLine("Page:{0} IsInverted:{1} RotationAngle:{2} DeskewAngle{3}", e.ImagePageNumber, values.IsInverted, values.RotationAngle, values.DeskewAngle);// Load the original image from diskvar overlayImage = e.Document.RasterCodecsInstance.Load(e.Job.JobData.ImageFileName, e.ImagePageNumber);// Apply to the imageif (values.RotationAngle != 0)new RotateCommand(values.RotationAngle, RotateCommandFlags.None, RasterColor.FromKnownColor(RasterKnownColor.White)).Run(overlayImage);if (values.IsInverted)new InvertCommand().Run(overlayImage);e.Page.SetOverlayImage(overlayImage);}}};autoRecognizeManager.JobOperation += jobOperation;try{status = autoRecognizeManager.RunJob(job);}finally{autoRecognizeManager.JobOperation -= jobOperation;}Console.WriteLine(status);}}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Forms.OcrImports Leadtools.FormsImports Leadtools.Forms.DocumentWritersImports Leadtools.WinFormsImports Leadtools.DrawingImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorPublic Shared Sub SetOverlayImageExample()Dim originalFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1_Deskewed.tif")Dim outFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "result.pdf")Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)' Mimimc having an image that is deskewedUsing rasterImage As RasterImage = ocrEngine.RasterCodecsInstance.Load(originalFileName, 1)' Rotate the image by 5 degrees to mimic deskewDim rotateCommand As New RotateCommand(5 * 100, RotateCommandFlags.None, RasterColor.FromKnownColor(RasterKnownColor.White))rotateCommand.Run(rasterImage)ocrEngine.RasterCodecsInstance.Save(rasterImage, imageFileName, RasterImageFormat.CcittGroup4, 1)End Using' Now we are ready. We will create a PDF for the result with image over text overlay. And we will intercept creating' the overlay and use the original image instead' Use PDF with image/text optionDim pdfOptions As PdfDocumentOptions = DirectCast(ocrEngine.DocumentWriterInstance.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions)pdfOptions.ImageOverText = TrueocrEngine.DocumentWriterInstance.SetOptions(DocumentFormat.Pdf, pdfOptions)' Create an OCR AutoRecognize jobDim jobData As New OcrAutoRecognizeJobDatajobData.ImageFileName = imageFileNamejobData.FirstPageNumber = 1jobData.LastPageNumber = -1jobData.DocumentFileName = outFileNamejobData.Format = DocumentFormat.PdfDim autoRecognizeManager As IOcrAutoRecognizeManager = ocrEngine.AutoRecognizeManagerDim job As IOcrAutoRecognizeJob = autoRecognizeManager.CreateJob(jobData)' Setup pre-processing commandsautoRecognizeManager.EnableTrace = TrueautoRecognizeManager.PreprocessPageCommands.Clear()autoRecognizeManager.PreprocessPageCommands.Add(OcrAutoPreprocessPageCommand.All)Dim status As OcrAutoRecognizeManagerJobStatusDim jobOperation As EventHandler(Of OcrAutoRecognizeJobOperationEventArgs) =Sub(sender As Object, e As OcrAutoRecognizeJobOperationEventArgs)If e.Operation = OcrAutoRecognizeManagerJobOperation.SavePage ThenIf Not e.PostOperation Then' Get the pre-processing values for the pageDim values As OcrPageAutoPreprocessValues = e.Page.GetPreprocessValues()' Show the status of itConsole.WriteLine("Page:{0} IsInverted:{1} RotationAngle:{2} DeskewAngle{3}", e.ImagePageNumber, values.IsInverted, values.RotationAngle, values.DeskewAngle)' Load the original image from diskDim overlayImage As RasterImage = e.Document.RasterCodecsInstance.Load(e.Job.JobData.ImageFileName, e.ImagePageNumber)' Apply to the imageIf values.RotationAngle <> 0 ThenDim rotateCmd As New RotateCommand(values.RotationAngle, RotateCommandFlags.None, RasterColor.FromKnownColor(RasterKnownColor.White))rotateCmd.Run(overlayImage)End IfIf (values.IsInverted) ThenDim invertCmd As New InvertCommand()invertCmd.Run(overlayImage)End Ife.Page.SetOverlayImage(overlayImage)End IfEnd IfEnd SubAddHandler autoRecognizeManager.JobOperation, jobOperationTrystatus = autoRecognizeManager.RunJob(job)FinallyRemoveHandler autoRecognizeManager.JobOperation, jobOperationEnd TryConsole.WriteLine(status)End UsingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime"End Class
Leadtools.Forms.DocumentWriters.DocumentFormat
|
Products |
Support |
Feedback: SetOverlayImage Method - Leadtools.Forms.Ocr |
Introduction |
Help Version 19.0.2017.6.6
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.