16,551
社区成员
发帖
与我相关
我的任务
分享DrawBoneStroke(HDC pdc,Graphics* graphic,Pen* smoothpen,Point* src, int npoints,COLORREF color,double* prePw)
{
if (npoints<7)
return;
double distance;
double delx,dely;
double pw;
double constant;
double averageDis = 0;
BOOL bDiginoteStroke = FALSE;
smoothpen->SetColor(Color(75,GetRValue(color),GetGValue(color),GetBValue(color)));
for (int i=0;i<npoints-1;i++)
{
delx = src[i].X - src[i+1].X;
dely = src[i].Y - src[i+1].Y;
distance = sqrt((double)delx*delx + dely*dely);
averageDis += distance;
}
if (averageDis<15)
return;
averageDis /= (npoints-1);
//averageDis = 2.00;
if (PenWidth != 1)
constant = 20;
else
{
constant = averageDis;
bDiginoteStroke = TRUE;
}
for (int i=0;i<npoints-1;i++)
{
//只画前3个点和后三个//////////////////////
if((i>3 && i<npoints-3) && bDiginoteStroke == TRUE)
{
continue;
}
////////end of 只画前3个点//////
delx = src[i].X - src[i+1].X;
dely = src[i].Y - src[i+1].Y;
distance = sqrt((double)delx*delx + dely*dely);
if (distance == 0)
pw = 1;
else
pw = constant/distance;
if (PenWidth == 1)
{
if (pw<1)
{
pw =1;
}
if (pw > PenWidth)
{
pw = PenWidth+1;
}
}
else
{
if (pw<2)
{
pw = 2;
}
if (pw>PenWidth)
{
pw = PenWidth;
}
}
if (i==0)
{
smoothpen->SetWidth(pw);
graphic->DrawLine(smoothpen,src[i],src[i+1]);
(*prePw) = pw;
continue;
}
if ((pw-(*prePw))>0.5)
pw = (*prePw) + 0.5;
else if (((*prePw)-pw)>0.5)
pw = (*prePw) - 0.5;
else
pw = (*prePw);
smoothpen->SetWidth(pw);
graphic->DrawLine(smoothpen,src[i],src[i+1]);
(*prePw) = pw;
}