//前面请参照之前的文章
void CBMPViewerDoc::OnMenuitem32797() //轮廓提取 适合已经转变为二值图像
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int sum;
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = 255;
}
else{
sum = 0;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
sum += *lpScr;
}
}
if(sum %9 !=0 )
{
*lpDest = 0;
}
else *lpDest= 255;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
//
Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}