BorderRemove example for C++ 5.0 and later
void CTutorDlg::OnBorderRemove()
{
//Border Remove
//This example returns a region corresponding to the borders of a bitmap
//For the example, windows regions are returned in the BorderRemove Event and combined.
//In practice it would be easier and faster to just return a LEAD region representing the changes
//The border is removed from the image
//The following is declared and created in in the CTutorDlg class constructor
// ILEADRasterProcess *m_pRasterProc=NULL;
// hr = CoCreateInstance(
// CLSID_LEADRasterProcess,
// NULL,
// CLSCTX_ALL,
// IID_ILEADRasterProcess,
// (void**)&m_pRasterProc);
//
//The following is declared in the CTutorDlg class
// HRGN m_hRgnAll;
//
//NOTE: This is not a complete example for handing events, some steps have been omitted.
//For a complete example of how to handle events, refer to the example
//Updating a Gauge and Detecting a User Interrupt.
int nRet;
m_LEADRasterView1.GetRaster().UnlockSupport(L_SUPPORT_DOCUMENT, L_KEY_DOCUMENT);
m_pRasterProc->EnableMethodErrors = FALSE;
//Enable the doc clean event
m_pRasterProc->EnableDocCleanEvents = TRUE;
//Create a NULL region
m_hRgnAll = NULL;
m_hRgnAll = CreateRectRgn(0, 0, 0, 0);
nRet = m_pRasterProc->BorderRemove(
m_LEADRasterView1.GetRaster(),
(BorderRemoveFlags)(BORDER_CALLBACK_REGION | BORDER_USE_VARIANCE),
BORDER_ALL,
20,
9,
3);
if (nRet == 0)
{
m_LEADRasterView1.GetRaster().FreeRgn();
m_LEADRasterView1.GetRaster().SetRgnHandle((long)m_hRgnAll, 0, 0, L_RGN_SET);
m_LEADRasterView1.SetRgnFrameType(RGNFRAME_COLOR);
}
//delete the Windows Rgn
DeleteObject(m_hRgnAll);
m_hRgnAll = NULL;
}
void CRasterProcSink::OnBorderRemov(
long hRgn,
long uBorderToRemove,
float fBoundingRectLeft,
float fBoundingRectTop,
float fBoundingRectWidth,
float fBoundingRectHeight)
{
TCHAR pszBorder = TEXT("");
CString strMsg;
CombineRgn(m_pDlg->m_hRgnAll, m_pDlg->m_hRgnAll, (HRGN)hRgn, RGN_OR);
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;
}
strMsg.Format(TEXT("Border[%s] Bounds[Left,Top,Width,Height][%0.0f,%0.0f %0.0f,%0.0f]\n"),
pszBorder,
fBoundingRectLeft,
fBoundingRectTop,
fBoundingRectWidth,
fBoundingRectHeight);
OutputDebugString(strMsg);
m_pDlg->m_pRasterProc->DocCleanSuccess = SUCCESS_NOREMOVE;
}