Hi,
I'm trying to binarize a bitmap with L_AutoBinarizeBitmap and call L_BorderRemoveBitmap after that, the problem is that i get a ERROR_BITPERPIXEL error on the BorderRemove method. Here is my code:
L_INT Doc2AddPageExample(L_HDOC2 hDoc,L_TCHAR* pszFileName)
{
L_INT nRet;
BITMAPHANDLE Bitmap;
L_INT nPageCount = 0;
L_TCHAR szBuffer[100];
memset(szBuffer, 0, sizeof(szBuffer));
nRet = L_InitBitmap(&Bitmap, sizeof(BITMAPHANDLE), 0, 0,0);
if(nRet != SUCCESS)
return nRet;
nRet = L_LoadBitmap(pszFileName, &Bitmap, sizeof(BITMAPHANDLE),0, ORDER_BGRORGRAY, NULL, NULL);
if (nRet != SUCCESS)
return nRet;
nRet = L_AutoBinarizeBitmap( &Bitmap, 0, AUTO_BINARIZE_PRE_BG_ELIMINATION | AUTO_BINARIZE_THRESHOLD_AUTO);
if (nRet != SUCCESS)
return nRet;
nRet = BorderRemoveBitmapExample( &Bitmap);
if (nRet != SUCCESS)
return nRet;
nRet = L_Doc2AddPage(hDoc, &Bitmap, 0);
if (nRet != SUCCESS)
return nRet;
nRet = L_Doc2GetPageCount (hDoc, &nPageCount);
return SUCCESS;
}
L_INT BorderRemoveBitmapExample(pBITMAPHANDLE pBitmap)
{
L_INT32 nRet;
BORDERREMOVE br;
BITMAPHANDLE RegionBitmap;
memset(&RegionBitmap, 0, sizeof(BITMAPHANDLE));
//Create a NULL region
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_USE_VARIANCE;
br.pBitmapRegion = &RegionBitmap;
br.uBitmapStructSize = sizeof(BITMAPHANDLE);
nRet = L_BorderRemoveBitmap( pBitmap,&br,NULL,NULL,0);
if (nRet == SUCCESS)
{
RECT rectRgn;
HRGN hRgnAll;
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 nRet;
}
Can someone help me figure out how to make it work ?
Thank you,
Yassine