#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_GetBitmap(page, bitmapType, bitmapHandle, bitmapHandleSize)

L_OcrPage page; handle to the OCR page
L_OcrPageBitmapType bitmapType; the page type to get
BITMAPHANDLE* bitmapHandle; address to BITMAPHANDLE variable to be updated with the page bitmap
L_UINT bitmapHandleSize; size of the BITMAPHANDLE structure

Gets the original or processing btimap data of this page as a bitmap handle.

Parameter Description
page Handle to the OCR page.
bitmapType The page type to get.
bitmapHandle Address to BITMAPHANDLE variable to be updated with the page bitmap.
bitmapHandleSize Size of the BITMAPHANDLE structure, use sizeof(BITMAPHANDLE).


SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.


Each L_OcrPage contains two versions of the image used to create it: an original and an optional processing version. The processing version usually black/white and has uniform resolution (if the original image is FAX for example) and it gets passed to the internal OCR engine during the zoning and recognition process. The L_OcrPage_AutoPreprocess method also uses the B/W image to determine if the page is inverted, skewed, or has an orientation. However, it applies the correction to both the current and processing images.

You can use L_OcrPage_GetBitmap to get a copy of the processing image, but as for the original image this function returns a reference to the original bitmap handle (not a copy) so you should not call L_FreeBitmap on this bitmap type.

You cannot set the processing image of a page; it is created automatically by the engine.

If the original image is black and white and has uniform vertical and horizontal resolution, then the engine will not create a processing image, in other words, L_OcrPage_GetBitmap will return identical BTIMAPHANDLE for both original and processing bitmap types.

If the original image has different horizontal and vertical resolution, such as a FAX image, the processing page will be have be resized to have uniform resolution.

Required DLLs and Libraries

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.
See Also
Functions: L_OcrPage_Destroy, L_OcrPage_FromBitmap, L_OcrPage_SetBitmap, L_OcrPage_GetOverlayBitmap, L_OcrPage_SetOverlayBitmap, L_OcrPage_SetBitmapChangedCallback, L_OcrPage_IsInverted, L_OcrPage_GetRotateAngle, L_OcrPage_GetDeskewAngle, L_OcrPage_AutoPreprocess, L_OcrPage_AutoZone, L_OcrPage_GetZoneCount, L_OcrPage_InsertZone, L_OcrPage_AddZone, L_OcrPage_IndexOfZone, L_OcrPage_GetZoneAt, L_OcrPage_SetZoneAt, L_OcrPage_RemoveZone, L_OcrPage_RemoveZoneAt, L_OcrPage_ClearZones, L_OcrPage_GetZoneCells, L_OcrPage_SetZoneCells, L_OcrPage_HitTestZone, L_OcrPage_IsRecognized, L_OcrPage_Recognize, L_OcrPage_Unrecognize, L_OcrPage_GetRecognizeStatistics, L_OcrPage_GetRecognizedCharacters, L_OcrPage_SetRecognizedCharacters, L_OcrPage_FreePageCharacters, L_OcrPage_GetZoneWords, L_OcrPage_FreeWords, L_OcrPage_GetText, L_OcrPage_ExtractZoneMICRData, L_OcrPage_DetectLanguages, L_OcrPage_LoadZonesFile, L_OcrPage_SaveZonesFile, L_OcrPage_SaveXml, L_OcrPage_GetAutoPreprocessValues
Topics: Programming with LEADTOOLS OCR Module - LEAD Engine
Starting and Shutting Down the OCR Engine
Recognizing OCR Pages
Working With OCR Pages


L_INT L_OcrPage_GetBitmapExample() 
   int bitsPerPixel = 0; 
   int qualityFactor = 2; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrPage ocrPage = NULL; 
   BITMAPHANDLE bitmap = {0}, exportPage = {0}; 
   pFILEINFO fileInfo = NULL; 
   L_OcrProgressCallback callback = NULL; 
   L_VOID* userData = NULL; 
   // Create an instance of the engine 
   L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
   // Start the engine using default parameters 
   retCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
   if(retCode != SUCCESS) 
      goto CLEANUP; 
   // Load an image file 
   retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), bitsPerPixel, ORDER_RGB, loadOpts, fileInfo); 
   if(retCode != SUCCESS) 
      goto CLEANUP; 
   // Add the raster image into the OCR page 
   retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, callback, userData); 
   if(retCode != SUCCESS) 
      goto CLEANUP; 
   // At this point, we have a valid page and bitmap ownership has transfered, so, we do not need to free the bitmap anymore 
   bitmap.Flags.Allocated = 0; 
   retCode = L_OcrPage_GetBitmap(ocrPage, L_OcrPageBitmapType_Original, &exportPage, sizeof(BITMAPHANDLE)); 
   if(retCode != SUCCESS) 
      goto CLEANUP; 
   // Save this image to disk 
   bitsPerPixel = 24; 
   L_SaveBitmap(MAKE_IMAGE_PATH(L_TEXT("OcrExported.jpg")), &exportPage, FILE_JPEG, bitsPerPixel, qualityFactor, saveOpts); 
   if(ocrPage != NULL) 
   return retCode; 

Help Version 20.0.2018.1.19
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.