L_BorderRemoveBitmap
#include "l_bitmap.h"
L_LTIMGCOR_API L_INT L_BorderRemoveBitmap(pBitmap, pBorderRemove, pfnCallback, pUserData, uFlags)
pBITMAPHANDLE pBitmap; |
/* pointer to the bitmap */ |
pBORDERREMOVE pBorderRemove; |
/* pointer to a structure */ |
BORDERREMOVECALLBACK pfnCallback; |
/* optional callback function */ |
L_VOID *pUserData; |
/* pointer to more parameters for the callback */ |
L_UINT32 uFlags; |
/* flags*/ |
Removes the black borders in a 1-bit black and white image.
Parameter |
Description |
pBitmap |
Pointer to the bitmap handle referencing the bitmap from which to remove borders. |
pBorderRemove |
Pointer to the BORDERREMOVE structure that LEADTOOLS uses to remove borders. |
pfnCallback |
Optional callback function for additional processing. |
|
If you do not provide a callback function, use NULL as the value of this parameter. |
|
If you do provide a callback function, use the function pointer as the value of this parameter. |
|
The callback function must adhere to the function prototype described in BORDERREMOVECALLBACK Function. |
pUserData |
Void pointer that you can use to pass one or more additional parameters that the callback function needs. |
|
To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. |
|
If the additional parameters are not needed, you can pass NULL in this parameter. |
uFlags |
Reserved for future use. Must be 0. |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
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.
(Document) This function removes borders that commonly appear in scanned text documents. Any or all of the four borders can be detected and removed. The behavior of this function can be modified by using its callback.
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.
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.
Required DLLs and Libraries
LTIMGCOR For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
Platforms
Windows 2000 / XP/Vista.
See Also
Example
This example returns a region corresponding to the borders of a bitmap For the example, windows regions are returned in the callback and combined. Inn practice it would easier and faster to just return a LEAD region representing the changes The border is removed from the image
#if defined (LEADTOOLS_V16_OR_LATER) L_INT EXT_CALLBACK ExampleBorderRemoveCB(HRGN hRgn, L_UINT32 uBorderToRemove, LPRECT pBoundingRect, L_VOID * pUserData) { L_TCHAR szMsg[200]; L_TCHAR *pszBorder=NULL; HRGN hRgnAll; hRgnAll = (HRGN)(pUserData); CombineRgn( hRgnAll, hRgnAll, hRgn, RGN_OR); DeleteObject(hRgn); switch (uBorderToRemove) { case BORDER_TOP: pszBorder = TEXT("Top"); break; case BORDER_LEFT: pszBorder = TEXT("Left"); break; case BORDER_RIGHT: pszBorder = TEXT("Right"); break; case BORDER_BOTTOM: pszBorder = TEXT("Bottom"); break; } wsprintf( szMsg, TEXT("Border[%s]\tBounds[%d,%d][%d,%d]\n"), pszBorder, pBoundingRect->left, pBoundingRect->top, pBoundingRect->right, pBoundingRect->bottom ); OutputDebugString(szMsg); return SUCCESS_REMOVE; } L_INT BorderRemoveBitmapExample(pBITMAPHANDLE pBitmap) { L_INT32 nRet; BORDERREMOVE br; HRGN hRgnAll; BITMAPHANDLE RegionBitmap; memset(&RegionBitmap, 0, sizeof(BITMAPHANDLE)); //Create a NULL region hRgnAll = CreateRectRgn(0, 0, 0, 0); br.uStructSize = sizeof(BORDERREMOVE); 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 = &RegionBitmap; br.uBitmapStructSize = sizeof(BITMAPHANDLE); nRet = L_BorderRemoveBitmap( pBitmap, &br, ExampleBorderRemoveCB, (L_VOID *)hRgnAll , 0); if (nRet == SUCCESS) { RECT rectRgn; GetRgnBox(hRgnAll, &rectRgn); if (!IsRectEmpty(&rectRgn)) { nRet = L_SetBitmapRgnHandle(pBitmap, NULL, hRgnAll, L_RGN_SET); if(nRet != SUCCESS) return nRet; DeleteObject(hRgnAll); } } else { return nRet; } return SUCCESS; } #else L_INT EXT_CALLBACK ExampleBorderRemoveCB(HRGN hRgn, L_UINT32 uBorderToRemove, LPRECT pBoundingRect, L_VOID * pUserData) { L_TCHAR szMsg[200]; L_TCHAR *pszBorder=NULL; HRGN hRgnAll; hRgnAll = (HRGN)(pUserData); CombineRgn( hRgnAll, hRgnAll, hRgn, RGN_OR); DeleteObject(hRgn); switch (uBorderToRemove) { case BORDER_TOP: pszBorder = TEXT("Top"); break; case BORDER_LEFT: pszBorder = TEXT("Left"); break; case BORDER_RIGHT: pszBorder = TEXT("Right"); break; case BORDER_BOTTOM: pszBorder = TEXT("Bottom"); break; } wsprintf( szMsg, TEXT("Border[%s]\tBounds[%d,%d][%d,%d]\n"), pszBorder, pBoundingRect->left, pBoundingRect->top, pBoundingRect->right, pBoundingRect->bottom ); OutputDebugString(szMsg); return SUCCESS_REMOVE; } L_INT BorderRemoveBitmapExample(pBITMAPHANDLE pBitmap) { L_INT32 nRet; BORDERREMOVE br; HRGN hRgnAll; BITMAPHANDLE RegionBitmap; memset(&RegionBitmap, 0, sizeof(BITMAPHANDLE)); //Create a NULL region hRgnAll = CreateRectRgn(0, 0, 0, 0); br.uStructSize = sizeof(BORDERREMOVE); 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 = &RegionBitmap; br.uBitmapStructSize = sizeof(BITMAPHANDLE); nRet = L_BorderRemoveBitmap( pBitmap, &br, ExampleBorderRemoveCB, (L_VOID *)hRgnAll ); if (nRet == SUCCESS) { RECT rectRgn; GetRgnBox(hRgnAll, &rectRgn); if (!IsRectEmpty(&rectRgn)) { nRet = L_SetBitmapRgnHandle(pBitmap, NULL, hRgnAll, L_RGN_SET); if(nRet != SUCCESS) return nRet; DeleteObject(hRgnAll); } } else { return nRet; } return SUCCESS; } #endif // LEADTOOLS_V16_OR_LATER