Removes the black borders in a 1-bit black and white image.
#include "ltwrappr.h"
virtual L_INT LBitmap::BorderRemove(pBorderRemove, uFlags = 0)
Pointer to the BORDERREMOVE structure that LEADTOOLS uses to remove borders.
Reserved for future use. Must be 0.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
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 - After
View additional platform support for this Border Remove function.
Win32, x64.
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 Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document