virtual L_INT LBitmap::HolePunchRemove(pHolePunchRemove, uFlags = 0)
Finds and removes hole punches.
Pointer to the HOLEPUNCH structure that LEADTOOLS uses to remove hole punches.
Reserved for future use. Must be 0.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
This function detects and removes hole punch marks that are common in scanned documents.
The behavior of this function can be modified by overriding LBitmap::HolePunchRemoveCallback.
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 works only on 1-bit black and white images.
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.
Hole punch configurations may consist of 2 or more holes.
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.
Before calling this function, ensure that the hole punch is free of any other stray marks. If you do not, LBitmap::HolePunchRemove will not recognize the hole.
For example, the below image must have the vertical line removed. Use LBitmap::LineRemove to remove any horizontal or vertical lines from the image. Use other Document Cleanup functions to remove other imaging artifacts such as dots, blobs, borders, inverted text, bumps and nicks. This will have the added benefit of making your image smaller when compressed.
Once cleaned, LBitmap::HolePunchRemove will be able to identify and remove the hole punch mark.
Win32, x64.
This example updates a Windows region with removed hole punches
For the example, a Windows region is updated and then converted to a LEAD region
but in practice it would easier and faster to just return a LEAD region
The HOLEPUNCH_USE_DPI flag instructs the API to determine the size of the hole punches
based on the image DPI
The image is modified
The derived class LMyBitmap is used to override the HolePunchRemoveCallBack function
The callback member function is used to display information about each hole punch removed
The callback member function does NOT receive a Windows region
class LHolePunchRemoveBitmap : public LBitmap
{
public:
LHolePunchRemoveBitmap();
~LHolePunchRemoveBitmap();
virtual L_INT HolePunchRemoveCallBack(HRGN hRgn,
PRECT pBoundingRect,
L_INT32 iHoleIndex,
L_INT32 iHoleTotalCount,
L_INT32 iWhiteCount,
L_INT32 iBlackCount
);
};
LHolePunchRemoveBitmap::LHolePunchRemoveBitmap()
{
}
LHolePunchRemoveBitmap::~LHolePunchRemoveBitmap()
{
}
L_INT LBitmap__HolePunchRemoveExample(LBitmapWindow *pBitmapWindow)
{
L_INT32 nRet;
HOLEPUNCH hr;
hr.uStructSize = sizeof(HOLEPUNCH);
hr.iLocation = HOLEPUNCH_LEFT;
hr.iMinHoleCount = 2;
hr.iMaxHoleCount = 4;
hr.pBitmapRegion = NULL;
hr.uFlags = HOLEPUNCH_SINGLE_REGION | HOLEPUNCH_USE_DPI | HOLEPUNCH_USE_COUNT | HOLEPUNCH_USE_LOCATION;
nRet = pBitmapWindow->HolePunchRemove(&hr);
if (nRet == SUCCESS)
{
//Delete the existing region
LBitmapRgn Region(pBitmapWindow);
if(Region.BitmapHasRgn())
{
Region.Free();
}
Region.SetRgnCombineMode(L_RGN_SET) ;
Region.SetRgnHandle(hr.hRgn);
DeleteObject(hr.hRgn);
}
return SUCCESS;
}
L_INT LHolePunchRemoveBitmap::HolePunchRemoveCallBack(
HRGN hRgn,
PRECT pBoundingRect,
L_INT32 iHoleIndex,
L_INT32 iHoleTotalCount,
L_INT32 iWhiteCount,
L_INT32 iBlackCount
)
{
UNREFERENCED_PARAMETER(hRgn);
CString strMsg;
strMsg.Format (
TEXT("Bounds[%d,%d][%d,%d]\tHole[%d] of [%d]\tWhiteCount[%d]\tBlackCount[%d]\n"),
pBoundingRect->left,
pBoundingRect->top,
pBoundingRect->right,
pBoundingRect->bottom,
iHoleIndex,
iHoleTotalCount,
iWhiteCount,
iBlackCount
);
OutputDebugString(strMsg);
return SUCCESS_REMOVE;
}
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