源自:http://blog.sina.com.cn/s/blog_6b41baed0100nmps.html
//于八方向链码的边界跟踪代码,其中nVerct数组存储的是边界点的矢量方向,Coordinate存储的是边界点的坐标。
BOOL CDib::PickBoundary(BYTE* nVerct,int (*Coordinate)[2])
{
if(NULL == m_lpBits)
struct EdgePoint
{
};
//CArray <EdgePoint,EdgePoint&> TraceArray;
//获取位图的宽,高,以及每行字节数
int nWidth=m_nWidth;
int nHeight=m_nHeight;
int nByteWidth=BYTE_PER_LINE(m_nWidth,m_nBitCount);
//循环变量
int i,j;
//开辟一块新的空间并初始化
BYTE *pData=new BYTE[nByteWidth*nHeight];
memset(pData,255,nByteWidth*nHeight);
//像素值
unsigned char pixel;
//是否找到起始点及回到起始点
bool bFindStartPoint;
//是否扫描到一个边界点
bool bFindPoint;
typedef struct
{
}Position;
//起始边界点与当前边界点
Position StartPoint,CurrentPoint;
//八个方向和起始扫描方向,依次是左上方、上方、右上方、右方、右下方、下方、左下方和左方。
int Direction[8][2]={ {-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0} };
int BeginDirect;
//先找到最左下方的边界点
bFindStartPoint = false;
for (j = 1;j < nHeight-1 && !bFindStartPoint;j++)
{
}
//由于起始点是在左下方,故起始扫描沿左上方向
BeginDirect = 0;
//跟踪边界
bFindStartPoint = false;
CurrentPoint.Height = StartPoint.Height;
CurrentPoint.Width = StartPoint.Width;
int index=0;
memset(nVerct,0,9999);
while(!bFindStartPoint)
{
}
//边界跟踪时,边界点数
m_nNumNode =index;
memcpy(m_lpBits,pData,nByteWidth*nHeight);
delete pData;
return TRUE;
}