注册 登录
编程论坛 C图形专区

填充函数怎么用呀?

蔡蔡 发布于 2007-06-18 11:20, 1075 次点击
填充函数要怎么用呀?是不是要设什么颜色,还要什么模式,然后直接填就行了吗?
为什么我填充后只是白色的屏幕而已~
3 回复
#2
neverTheSame2007-06-18 13:56

首先使用填充函数之前要确定,需要填充的区域是封闭的,否则会出现全屏填充的情况.
其次还要知道需要填充的区域的边线的颜色.
然后,设置填充模式,用函数setfillstyle()来设置.
最后,用floodfill(x,y,color)来填充,其中,x,y为需要填充的区域的任意一点,color为边线颜色.

#3
蔡蔡2007-06-18 17:03
回复:(neverTheSame)首先使用填充函数之前要确定,需...
我用drawpoly画了一个四方形,应该是封闭的吧~
我用红色填充,怎么变成整个画面都是白色的?
可能是我没有设置模式吧~~
你能不能举一个例子来说明说明?非常感谢!!!
#4
neverTheSame2007-06-19 18:12

#include <stdio.h>
#include <conio.h>
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
int poly[10];
initgraph(&gdriver, &gmode,"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx = getmaxx();
maxy = getmaxy();
poly[0] = 20;
poly[1] = maxy / 2;
poly[2] = maxx - 20;
poly[3] = 20;
poly[4] = maxx - 50;
poly[5] = maxy - 20;
poly[6] = maxx / 2;
poly[7] = maxy / 2;
poly[8] = poly[0];/*保证图形是封闭*/
poly[9] = poly[1];
drawpoly(5, poly);/*一定要是封闭*/

getch();

setfillstyle(1,RED);
floodfill(200,maxy/2-50,15);

getch();
closegraph();
return 0;
}

1