19,468
社区成员
发帖
与我相关
我的任务
分享
void CFillTudouDlg::OnButton1()
{
// TODO: Add your control notification handler code here
BOOL start=FALSE;
int end=0;
CDC *pDC=m_Pic.GetDC();
CRect rc;
m_Pic.GetClientRect(rc);
CRgn allRgn,tmpRgn;
allRgn.CreateRectRgn(0,0,0,0);
//
for(int y=0;y < rc.Height();y++)
{
for(int x=0;x < rc.Width();x++)
{
COLORREF col=pDC->GetPixel(x,y);
if((!start) && (col == RGB(0,0,0)))
{// once a line
start=TRUE;
// find end
int e=x;
int repeat=x;
// skip as many as black points
while((pDC->GetPixel(e,y) == RGB(0,0,0)) && (e < rc.Width()))
{
e++;
repeat++;
}
// search end
while((pDC->GetPixel(e,y) != RGB(0,0,0)) && (e < rc.Width()))
{
e++;
}
// if after end ,still black points
while((pDC->GetPixel(e,y) == RGB(0,0,0)) && (e < rc.Width()))
{
e++;
}
// check valid x
if(e == rc.Width())
{// not found
end=repeat;
}
else
{// found
end=e;
}
}// end if((!start) && (col == RGB(0,0,0)))
// add rgn
if(start && (x < end))
{
#if 1 // not use rgn
pDC->SetPixel(x,y,RGB(255,0,0));
#else
tmpRgn.CreateRectRgn(x,y,x+1,y+1);
allRgn.CombineRgn(&allRgn,&tmpRgn,RGN_OR);
tmpRgn.DeleteObject();
#endif
}
}// end for x
// reset flag
start=FALSE;
}// end for y
#if 0
//draw rgn
CBrush br;
br.CreateSolidBrush(RGB(255,0,0));
pDC->FillRgn(&allRgn,&br);
ReleaseDC(pDC);
#endif
}