C++给不规则图形填充颜色
我用VC++写的一个给不规则推行填充颜色的程序,能够正常运行,但是在填充后没有任何颜色显示,把颜色改了很多次也不行!!下面是代码,麻烦高手知道下:CDC*pDC=GetDC();
int i,n=6;
CPoint B[6]={CPoint(30,180),CPoint(30,390),CPoint(210,240),CPoint(390,360),CPoint(390,210),CPoint(180,30)};
int xmax=B[0].x,ymax=B[0].y,xmin=B[0].x,ymin=B[0].y;
for(i=1;i<=n;i++)
{
if(xmin>B[i].x)
xmin=B[i].x;
if(xmax<B[i].x)
xmax=B[i].x;
if(ymin>B[i].y)
ymin=B[i].y;
if(ymax<B[i].y)
ymax=B[i].y;
}
pDC->MoveTo(B[0]);
for(i=1;i<=n;i++)
{
pDC->LineTo(B[i%n]);
}
int a,m=4,x,y,flag,C1=(50,50,50),C2=RGB(255,50,250);
CPoint C[4]={CPoint(xmin,ymin),CPoint(xmin,ymax),CPoint(xmax+30,ymax),CPoint(xmax+30,ymin)};
pDC->MoveTo(C[0]);
for(a=1;a<=m;a++)
{
pDC->LineTo(C[a%m]);
}
for(y=ymin;y<=ymax;y++)
{
flag=-1;
for(x=xmin;x<=xmax;x++)
{
if(pDC->GetPixel(x-1,y)==C1)
flag=-flag;
if(flag==1)
pDC->SetPixel(x,y,C2);
}
}