←Select platform

CreateThumbnail Method

Summary
Creates a thumbnail image of this IOcrPage.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public RasterImage CreateThumbnail( 
   int thumbnailWidth, 
   int thumbnailHeight 
) 
- (nullable LTRasterImage *)createThumbnailWithWidth:(NSUInteger)thumbnailWidth height:(NSUInteger)thumbnailHeight error:(NSError **)error NS_SWIFT_NAME(createThumbnail(width:height:)); 
public RasterImage createThumbnail(int thumbnailWidth, 
                                   int thumbnailHeight) 
RasterImage^ CreateThumbnail(  
   int thumbnailWidth, 
   int thumbnailHeight 
)  
def CreateThumbnail(self,thumbnailWidth,thumbnailHeight): 

Parameters

thumbnailWidth
The desired maximum width of the thumbnail image in pixels.

thumbnailHeight
The desired maximum height of the thumbnail image in pixels.

Return Value

A RasterImage object that contains a thumbnail of this IOcrPage.

Remarks

The thumbnail image returned from this image always contain the correct aspect ratio. The width and height of the thumbnail is guaranteed to be at least  thumbnailWidth by  thumbnailHeight in size but never exceeding that. The only time you get a thumbnail that is exactly  thumbnailWidth by  thumbnailHeight pixels is when this IOcrPage is a perfect square.

The thumbnail image returned from this method will always contain 24 bits per pixel for best possible quality.

One use of the thumbnail image of a page is if your application is a Windows Forms-based application containing the ImageViewer control. You can use CreateThumbnail to obtain thumbnails of the pages in the engine and use them as items to the ImageViewer. For an example, refer to the C# Main OCR Demo that ships with LEADTOOLS.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Forms.Common; 
using Leadtools.Document.Writer; 
using Leadtools.WinForms; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
public void OcrPageExample() 
{ 
   string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
   string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf"); 
 
   // Create an instance of the engine 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      // Start the engine using default parameters 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
      // Create an OCR document 
      using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) 
      { 
         // Add this image to the document 
         IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null); 
 
         // Auto-recognize the zones in the page 
         ocrPage.AutoZone(null); 
 
         // Show its information 
         Console.WriteLine("Size: {0} by {1} pixels", ocrPage.Width, ocrPage.Height); 
         Console.WriteLine("Resolution: {0} by {1} dots/inch", ocrPage.DpiX, ocrPage.DpiX); 
         Console.WriteLine("Bits/Pixel: {0}, Bytes/Line: {1}", ocrPage.BitsPerPixel, ocrPage.BytesPerLine); 
 
         byte[] palette = ocrPage.GetPalette(); 
         int paletteEntries; 
         if (palette != null) 
            paletteEntries = palette.Length / 3; 
         else 
            paletteEntries = 0; 
 
         Console.WriteLine("Number of entries in the palette: {0}", paletteEntries); 
         Console.WriteLine("Original format of this page: {0}", ocrPage.OriginalFormat); 
         Console.WriteLine("Has this page been recognized? : {0}", ocrPage.IsRecognized); 
         ShowZonesInfo(ocrPage); 
 
         // Recognize it and save it as PDF 
         ocrPage.Recognize(null); 
         ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null); 
      } 
 
      // Shutdown the engine 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
      ocrEngine.Shutdown(); 
   } 
} 
 
private void ShowZonesInfo(IOcrPage ocrPage) 
{ 
   Console.WriteLine("Zones:"); 
   foreach (OcrZone ocrZone in ocrPage.Zones) 
   { 
      int index = ocrPage.Zones.IndexOf(ocrZone); 
      Console.WriteLine("Zone index: {0}", index); 
      Console.WriteLine("  Id                  {0}", ocrZone.Id); 
      Console.WriteLine("  Bounds              {0}", ocrZone.Bounds); 
      Console.WriteLine("  ZoneType            {0}", ocrZone.ZoneType); 
      Console.WriteLine("  CharacterFilters:   {0}", ocrZone.CharacterFilters); 
      Console.WriteLine("----------------------------------"); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.4.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Ocr Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.