L_OcrPage_SaveSvgMemory

#include "ltocr.h"

L_LTOCR_API L_INT L_OcrPage_SaveSvgMemory(page, handle, size)

Quickly saves the given page as an SVG stream.

Parameters

L_OcrPage page

Handle to the OCR page.

L_HANDLE *handle

Pointer to an L_HANDLE

L_SIZE_T *size

Pointer to an L_SIZE_T value that contains the number of bytes

Returns

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

Comments

This function will save the recognition result of this L_OcrPage in SVG format. Normally, the L_OcrDocument_Save must be used to save one or more pages to an output format. For the SVG format, use this function to quickly save the page and create the output document without having to create an OCR document handle first.

This function works whether the page is part of an OCR document or stands by itself.

To quickly save a given page as an SVG file, call L_OcrPage_SaveSvg.

Required DLLs and Libraries

Example

L_INT SAVESTREAMTOFILE(L_HANDLE hData, L_SIZE_T uSize, L_TCHAR* filename) { 
   HANDLE  hFile = NULL; 
   L_CHAR  *pDataMover; 
   DWORD dwSizeWrite; 
   BOOL result = TRUE; 
 
   // Lock the file to make it threadsafe 
   pDataMover = (L_CHAR*)GlobalLock(hData); 
 
   // Open/Create the file to write. 
   hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); 
 
   if (hFile == INVALID_HANDLE_VALUE) 
   { 
      result = FALSE; 
      goto CLEANUP; 
   } 
 
   // Write the file in a loop, because the file could be larger than a single write can request 
   while (uSize > 0) 
   { 
      result = WriteFile(hFile, pDataMover, (L_INT)min(uSize, (L_UINT32)32000), &dwSizeWrite, NULL); 
 
      if (!result) 
         goto CLEANUP; 
      else 
      { 
         uSize -= dwSizeWrite; 
         pDataMover += dwSizeWrite; 
      } 
   } 
 
CLEANUP: 
   if (hFile != INVALID_HANDLE_VALUE) 
      CloseHandle(hFile); 
   GlobalUnlock(hData); 
 
   return result ? SUCCESS : FAILURE; 
} 
 
L_INT L_OcrPage_SaveSvgMemoryExample() 
{ 
   L_INT retCode = SUCCESS; 
   L_OcrEngine ocrEngine = NULL; 
   BITMAPHANDLE bitmap = { 0 }; 
   L_OcrPage ocrPage = NULL; 
   L_HANDLE handle = NULL; 
   L_SIZE_T size = 0; 
 
   // Create an instance of the engine  
   retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_LEAD, &ocrEngine); 
   if (retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Start the engine using default parameters  
   retCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_LEAD_RUNTIME_DIR); 
   if (retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Load an image to process  
   retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
   if (retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Add the image to an OCR page  
   retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
   if (retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Transfer ownership to the OCR page  
   memset(&bitmap, 0, sizeof(bitmap)); 
 
   // Recognize it  
   retCode = L_OcrPage_Recognize(ocrPage, NULL, NULL); 
   if (retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Save the results directly to a file 
   retCode = L_OcrPage_SaveSvgMemory(ocrPage, &handle, &size); 
   if (retCode != SUCCESS) 
      goto CLEANUP; 
 
   retCode = SAVESTREAMTOFILE(handle, size, MAKE_IMAGE_PATH(L_TEXT("Ocr1.svg"))); 
   if (retCode != SUCCESS) 
      goto CLEANUP; 
 
CLEANUP: 
   if (handle != NULL) 
      GlobalFree(handle); 
   if (ocrPage != NULL) 
      L_OcrPage_Destroy(ocrPage); 
   if (bitmap.Flags.Allocated) 
      L_FreeBitmap(&bitmap); 
   if (ocrEngine != NULL) 
      L_OcrEngine_Destroy(ocrEngine); 
 
   return retCode; 
} 
Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.