这个程序要达到的目的是在窗口上显示的已经细化好的图片中右键点选一个起始点,然后按照八方向链码的顺序提取方向码,并最后在窗口上以数组的形式输出100个以内的链码值。现在的问题是,while循环得到的结果不对劲,后面用CClientDC显示的内容也显示不出来,
请各位高手帮帮忙了,谢谢!链码部分在这里void CMyDIPView::OnRButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
   StartPoint.x=point.x;                
   StartPoint.y=point.y;    CMyDIPDoc* pDoc = GetDocument();  
ASSERT_VALID(pDoc);
if(pDoc->m_hDIB == NULL)
return ;
// TODO: add draw code for native data here LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB);
int lWidth = (int) ::DIBWidth(lpDIB);         // Size of DIB - x
int lHeight = (int) ::DIBHeight(lpDIB);        // Size of DIB - y // 图像每行的字节数
LONG lLineBytes;
LPSTR lpDIBBits=::FindDIBBits (lpDIB);

//指向种子的像素指针
BYTE * start; //储存起点8邻域点像素值
BYTE image[8]; //储存链码过程中当前点邻域的像素值
BYTE doing[8];

// 计算图像每行的字节数
lLineBytes = WIDTHBYTES(lWidth * 8); //存储初始链码
    int *linkcode_before=(int *)malloc(sizeof(int)*lHeight*lWidth);  //存储归一化后链码
int *linkcode_after=(int *)malloc(sizeof(int)*lHeight*lWidth); 
    
    CString str;
    int i,k,t=0;
int num;
int num_doing;
long int count=0;
int x_start=0;
int y_start=0;
int x_edge;
int y_edge;
int line=500;
int num_white;
BOOL goon;    

//判断边缘是否结束

start = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - point.y) + point.x; if(* start==0)
{   
x_start=point.x;
y_start=point.y;
}

else 
{
image[0]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - point.y) + point.x+1);
        image[1]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 2 - point.y) + point.x+1);
        image[2]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 2 - point.y) + point.x);
        image[3]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 2 - point.y) + point.x-1);
        image[4]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - point.y) + point.x-1);
        image[5]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - point.y) + point.x-1);
        image[6]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - point.y) + point.x);
        image[7]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - point.y) + point.x+1);        num=8; for(i=0;i<8;i++)
{
if(image[i]==255)
continue;
else
{
                 num=i;
 break;
}
} if(num!=8)
{
if(num==0 || num==4)
y_start=point.y;
else if(num==1 || num==2 || num==3)
y_start=point.y+1;
else if(num==5 || num==6 || num==7)
y_start=point.y-1; if(num==0 || num==1 || num==7)
x_start=point.x+1;
else if(num==2 || num==6)
x_start=point.x;
else if(num==3 || num==4 || num==5)
x_start=point.x+1;
}

else
{
                   MessageBox("点击处及邻域内没有黑点,请重新选取!");
}
} if(x_start!=0)
{
x_edge=x_start;
y_edge=y_start; goon=true; while(goon)
{
goon=false;
        
doing[0]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - y_edge) + x_edge+1);
            doing[1]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 2 - y_edge) + x_edge+1);
            doing[2]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 2 - y_edge) + x_edge);
            doing[3]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 2 - y_edge) + x_edge-1);
            doing[4]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - y_edge) + x_edge-1);
            doing[5]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - y_edge) + x_edge-1);
            doing[6]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - y_edge) + x_edge);
            doing[7]=*((unsigned char*)lpDIBBits + lLineBytes * (lHeight - y_edge) + x_edge+1);            num_doing=8;
num_white=0;            for(k=0;k<8;k++)
{
if(doing[k]==255)
num_white++;
else if(count==0)
{
num_doing=k;
                linkcode_before[count]=k;
break;
}
else if((k!=linkcode_before[count]-4) && (k!=linkcode_before[count]+4))
{
                 num_doing=k;
 break;
}
else
continue;
}
if(num_doing==0 || num_doing==4)
y_edge=y_edge;
else if(num_doing==1 || num_doing==2 || num_doing==3)
y_edge++;
else if(num_doing==5 || num_doing==6 || num_doing==7)
y_edge--; if(num_doing==0 || num_doing==1 || num_doing==7)
x_edge++;
else if(num_doing==2 || num_doing==6)
x_edge=x_edge;
else if(num_doing==3 || num_doing==4 || num_doing==5)
x_edge--;
    if((count!=0 && x_edge==x_start && y_edge==y_start) ||(x_edge==0)||(x_edge==lWidth-1)||(y_edge==0)||(y_edge==lHeight-1)||(num_doing==8) || (num_white==7))
{
              goon=false;
}
else if(count<=100)
{              
      linkcode_before[count]=num_doing;
  count++;  
  goon=true;
}
else 
goon=false;
} }        CClientDC dc(this);

str.Format("图像链码为");
    dc.TextOut(500,400,str); for(t=0;t<count;t++)
{
              if(t%50==0)
  {
  str.Format(linkcode_before[t]);
  dc.TextOut(line,600+15*(t%50),str);
  line=line+10;
  str.Format("\n");
  dc.TextOut(line,600+15*(t%50),str);
  }
  else
  {
              str.Format(linkcode_before[t]);
  dc.TextOut(line,600+10*(t%50),str);
  line=line+10;
  }
}   
free(linkcode_before);
free(linkcode_after);     //解除锁定::GlobalUnlock((HGLOBAL) pDoc->m_hDIB);
 
CScrollView::OnRButtonDown(nFlags, point);
}