LPDFCompressor::InsertMRC

#include "ltwrappr.h"

#include "LTCPDFComp.h"

L_INT LPDFCompressor::InsertMRC(pBitmap, pPDFOptions)

Segments the specified image using MRC segmentation, compresses it, and inserts the image in the PDF file in memory.

Parameters

LBitmapBase* pBitmap

Pointer to the bitmap object that references the image to be inserted in the PDF file.

LPPDFCOMPOPTIONS pPDFOptions

Pointer to the PDFCOMPOPTIONS structure that contains options used to write the image to the PDF file in memory.

Returns

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

Comments

To insert the bitmap without using MRC segmentation, use LPDFCompressor::InsertNormal.

This function calls the LPDFCompressor::ImageCallBack, if LBase::EnableCallBack was set to TRUE, to allow the user to accept or reject the addition of any segment to the PDF document.

Required DLLs and Libraries

See Also

Functions

Topics

Example

This example inserts an image in a pdf document and uses MRC segmentation to segment this image. In this sample we don't need to add a background segment.

class LPDFCompressorKidIM : public LPDFCompressor  
{ 
protected:  
   L_INT ImageCallBack(L_INT nPage, LPSEGMENTINFO pSegment)  
   { 
      UNREFERENCED_PARAMETER(nPage); 
 
      if(pSegment->uSegmentType == SEGTYPE_BACKGROUND)  
         return FAILURE;  
      else 
         return SUCCESS;  
   } 
}; 
 
L_INT LPDFCompressor__InsertMRCExample(HWND hwnd)  
{ 
   LPDFCompressorKidIM  pdf ; 
   L_INT                nRet;  
   LBitmap              LEADBitmap;  
   PDFCOMPOPTIONS       PDFOptions;  
   PDFCOMPRESSION       pdfComp;  
   CString szMsg; 
   CString szImagesPath = MAKE_IMAGE_PATH(TEXT("IMAGE1.CMP")); 
   CString szOutPath = MAKE_IMAGE_PATH(TEXT("Output(InsertMRC).pdf")); 
 
    
   memset(&PDFOptions,0,sizeof(&PDFOptions));  
 
   pdf.EnableCallBack  (TRUE);  
 
   nRet = pdf.Init (); 
   if (nRet != SUCCESS)  
   { 
      MessageBox(hwnd, TEXT("Couldn't initialize pdf compressor"), TEXT("Error"), MB_OK) ;  
      return nRet; 
   } 
 
   pdfComp.uStructSize = sizeof( pdfComp );  
   pdfComp.dwFlags = PDFCOMP_1BITCOMPTYPE_ENABLED | PDFCOMP_2BITCOMPTYPE_ENABLED | PDFCOMP_PICTURECOMPTYPE_ENABLED;  
   pdfComp.comp1Bit = PDFCOMP_1BITCOMPTYPE_JBIG2;  
   pdfComp.comp2Bit = PDFCOMP_2BITCOMPTYPE_ZIP;  
   pdfComp.compPicture = PDFCOMP_PICTURECOMPTYPE_JPEG;  
   pdfComp.nQFactor =50;  
 
   nRet = pdf.SetCompression ( &pdfComp );  
   if(nRet != SUCCESS)  
   { 
      pdf.Free (); 
      return nRet; 
   } 
 
   PDFOptions.uStructSize = sizeof(PDFCOMPOPTIONS);  
   PDFOptions. dwFlags = PDFCOMP_FAVOR_ONEBIT | PDFCOMP_WITH_BACKGROUND;  
 
   PDFOptions.imageQuality = PDFCOMP_IMAGEQUALITY_USER;  
   PDFOptions.outputQuality = PDFCOMP_OUTPUTQUALITY_USER;  
 
   PDFOptions.uCleanSize = 7;    
   PDFOptions.uBackGroundThreshold = 15;  
   PDFOptions.uCombineThreshold = 100;  
   PDFOptions.uSegmentQuality = 50;  
   PDFOptions.uColorThreshold = 25;  
 
   nRet = LEADBitmap.Load((L_TCHAR *)(LPCTSTR)szImagesPath); 
   if(nRet != SUCCESS) 
   { 
      szMsg.Format(TEXT("Failed to load source image %s"),szImagesPath); 
      MessageBox(hwnd,szMsg, TEXT("Error"), MB_OK);  
      pdf.Free(); 
      return nRet; 
   } 
 
   nRet = pdf.InsertMRC(&LEADBitmap, &PDFOptions);  
   if(nRet != SUCCESS) 
      return nRet; 
 
   nRet = pdf.Write (((L_TCHAR *)(LPCTSTR)szOutPath)); 
   if (nRet ==SUCCESS)  
   { 
      szMsg.Format(TEXT("Result saved to %s"),szOutPath); 
      MessageBox( hwnd,szMsg, TEXT("Error"), MB_OK);  
   } 
   else 
   { 
      MessageBox( hwnd, TEXT("Failed to save result"), TEXT("Error"), MB_OK);  
 
      return nRet; 
   } 
 
   pdf.Free (); 
 
   return SUCCESS; 
} 

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

LEADTOOLS MRC C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.