Export the page at the specified index to a
RasterImage object.
Syntax
Parameters
- pageIndex
- The zero-based index of the page to export.
Return Value
A
RasterImage object containing a copy of the image data of the specified page.
Example
This example will add a page to an OCR document before exporting it back and saving it to disk
Visual Basic | Copy Code |
---|
Public Sub ExportPageToRasterImageExample()
RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here")
Dim tifFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif"
Dim exportedFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "OcrExported.jpg"
RasterCodecs.Startup()
Dim codecs As New RasterCodecs()
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
ocrEngine.Startup(codecs, Nothing, Nothing, Nothing)
Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()
ocrDocument.Pages.AddPage(tifFileName, Nothing)
Dim image As RasterImage = ocrDocument.Pages.ExportPage(0)
codecs.Save(image, exportedFileName, RasterImageFormat.Jpeg, 0)
image.Dispose()
End Using
ocrEngine.Shutdown()
End Using
codecs.Dispose()
RasterCodecs.Shutdown()
End Sub |
C# | Copy Code |
---|
public void ExportPageToRasterImageExample() { // Unlock the support needed for LEADTOOLS Plus OCR engine RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here"); string tifFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif"; string exportedFileName = LeadtoolsExamples.Common.ImagesPath.Path + "OcrExported.jpg"; RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); // Create an instance of the engine using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) { // Since we have a RasterCodecs object, re-use it in the OCR engine. Although // this demo will not use it, it is always a good practice ocrEngine.Startup(codecs, null, null, null); // Create an OCR document using(IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) { // Add the image to the document ocrDocument.Pages.AddPage(tifFileName, null); // Export it back as a RasterImage RasterImage image = ocrDocument.Pages.ExportPage(0); // Save this image to disk codecs.Save(image, exportedFileName, RasterImageFormat.Jpeg, 0); // We need to dispose the image ourselves image.Dispose(); } // Shutdown the engine // Note: calling Dispose will also automatically shutdown the engine if it has been started ocrEngine.Shutdown(); } codecs.Dispose(); RasterCodecs.Shutdown(); } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also