LBitmap::BorderRemove

Summary

Removes the black borders in a 1-bit black and white image.

Syntax

#include "ltwrappr.h"

virtual L_INT LBitmap::BorderRemove(pBorderRemove, uFlags = 0)

Parameters

pBORDERREMOVE pBorderRemove

Pointer to the BORDERREMOVE structure that LEADTOOLS uses to remove borders.

L_UINT32 uFlags

Reserved for future use. Must be 0.

Returns

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

Comments

This function removes borders that commonly appear in scanned text documents. Any or all of the four borders can be detected and removed.

This function works only on 1-bit black and white images.

If a region is selected, only the selected region will be changed by this function. If no region is selected, the whole image will be processed.

The behavior of this function can be modified by overriding LBitmap::BorderRemoveCallback.

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Border Remove Function - Before

Border Remove Function - Before

Border Remove Function - After

Border Remove Function - After

View additional platform support for this Border Remove function.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

This example updates a Windows region with the removed borders of a bitmap
The derived class LMyBitmap is used to override the BorderRemoveCallBack function
myBitmap is an object of class LMyBitmap.
For the example, Windows regions are received by the BorderRemoveCallBack function and combined.
In practice it would be easier and faster to just update a LEAD region with the changes
The borders are removed from the image.

class LBorderRemoveBitmap : public LBitmap 
{ 
public: 
   LBorderRemoveBitmap(); 
   ~LBorderRemoveBitmap(); 
 
   L_INT BorderRemoveCallBack(HRGN          hRgn,  
                              L_UINT32      uBorderToRemove,  
                              PRECT         pBoundingRect 
                              ); 
}; 
 
LBorderRemoveBitmap::LBorderRemoveBitmap() 
{ 
} 
 
LBorderRemoveBitmap::~LBorderRemoveBitmap() 
{ 
} 
 
L_INT LBorderRemoveBitmap::BorderRemoveCallBack(HRGN          hRgn,  
                                                L_UINT32      uBorderToRemove,  
                                                PRECT         pBoundingRect 
                                                ) 
{ 
     CString  strMsg; 
     CString  strBorder; 
     HRGN hRgnAll = NULL; 
 
     ::CombineRgn( hRgnAll, hRgnAll, hRgn,  RGN_OR); 
     DeleteObject(hRgn); 
 
     switch (uBorderToRemove) 
     { 
     case BORDER_TOP: 
        strBorder = TEXT("Top"); 
        break; 
 
     case BORDER_LEFT: 
        strBorder = TEXT("Left"); 
        break; 
 
     case BORDER_RIGHT: 
        strBorder = TEXT("Right"); 
        break; 
 
     case BORDER_BOTTOM: 
        strBorder = TEXT("Bottom"); 
        break; 
     } 
     strMsg.Format( 
        TEXT("Border[%s]\tBounds[%d,%d][%d,%d]\n"), 
        strBorder, 
        pBoundingRect->left, 
        pBoundingRect->top, 
        pBoundingRect->right, 
        pBoundingRect->bottom 
        ); 
     OutputDebugString(strMsg); 
 
     return SUCCESS_REMOVE;  
} 
 
L_INT LBitmap__BorderRemoveExample(LBitmapWindow *pBitmapWindow) 
{ 
  L_INT32        nRet; 
  BORDERREMOVE   br; 
  br.uStructSize = sizeof(BORDERREMOVE); 
  //Create a NULL region 
  RECT rect ={0, 0, 0, 0}; 
 
  pBitmapWindow->Region()->SetRgnRect(&rect); 
 
  br.uStructSize             = sizeof(DOTREMOVE); 
 
  br.uBitmapStructSize = sizeof(BITMAPHANDLE); 
 
  br.iBorderPercent    = 20; 
  br.iVariance         = 2; 
  br.iWhiteNoiseLength = 5; 
  br.uBorderToRemove   = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT; 
  br.uFlags            = BORDER_CALLBACK_REGION | BORDER_USE_VARIANCE; 
  br.pBitmapRegion     = NULL; 
 
  nRet = pBitmapWindow->BorderRemove(&br); 
 
  if (nRet == SUCCESS) 
  { 
     //Delete the existing region 
     LBitmapRgn Region(pBitmapWindow); 
     if(Region.BitmapHasRgn()) 
     { 
        Region.Free(); 
     } 
 
     Region.SetRgnCombineMode(L_RGN_SET) ; 
     Region.SetRgnHandle(pBitmapWindow->Region()->GetRgnHandle()); 
  } 
 
  return SUCCESS; 
} 

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

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