当前位置:首页 » 操作系统 » 填充算法

填充算法

发布时间: 2022-01-10 17:45:19

❶ 比较边界填充算法和泛填充算法的异同

如果是用线填充,程序如下。如果是用点填充需要用到堆栈和系统底层库函数或者用画点函数putpixel()。
下面实例是用扫描线填充长方形,开始要输入长方形的左上顶点坐标和右下顶点坐标以及填充扫描线的间距(>=1),如果间距等于1,就是完全填充(实填充)。
一个完整的c程序如下,程序在win-tc和tc2.0下都调试通过。
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>

void draw(int x1,int y1,int x2,int y2,int delta)
{int nx1,ny1,nx2,ny2; <br/>nx1=x1,ny1=y2-delta,nx2=x1+delta,ny2=y2; <br/>while((ny1>=y1)&&(nx2<=x2)) <br/>{line(nx1,ny1,nx2,ny2); <br/>ny1-=delta; <br/>nx2+=delta; <br/>}
if(nx2>x2)
{ny2-=nx2-x2; <br/>nx2=x2; <br/>while(ny1>y1) <br/>{line(nx1,ny1,nx2,ny2); <br/>ny1-=delta; <br/>ny2-=delta; <br/>}
nx1+=y1-ny1;
ny1=y1;
while(nx1<x2)
{line(nx1,ny1,nx2,ny2); <br/>nx1+=delta; <br/>ny2-=delta; <br/>}
}
else
{nx1+=y1-ny1; <br/>ny1=y1; <br/>while(nx2<x2) <br/>{line(nx1,ny1,nx2,ny2); <br/>nx2+=delta; <br/>nx1+=delta; <br/>}
ny2-=nx2-x2;
nx2=x2;
while(ny2>y1)
{line(nx1,ny1,nx2,ny2); <br/>ny2-=delta; <br/>nx1+=delta; <br/>}
}
}

int main(void)
{int x1,y1,y2,x2,delta; <br/>int driver=DETECT,mode; <br/>printf("Please input lefttop(x1,y1) and rightbottom(x2,y2) of rectangle and delta:\n"); <br/>scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&delta); <br/>initgraph (&driver,&mode,"C:\\TC"); /*这里*/<br/>rectangle(x1,y1,x2,y2); <br/>draw(x1,y1,x2,y2,delta); <br/>gotoxy(1,1); <br/>printf("Press any key to exit!"); <br/>getch()(); <br/>closegraph(); <br/>return 0; <br/>}

说明:将main()函数中的initgraph(&gdriver,&gmode,"");中的""更改为你的TC安装目录,一般tc必须安装在c盘根目录下,所以就是initgraph(&gdriver,&gmode,"C:\\TC");如你的TC安装目录为D盘的Tools目录下的TC目录,那么上述语句改为:
initgraph(&gdriver,&gmode,"D:\\Tools\\TC");
同时保证在D:\\Tools\\TC目录里有文件EGAVGA.BGI,万一不行,将本程序复制到你的TC安装目录下再运行。

❷ 边缘填充算法属于()算法一种。

边缘填充算法属于A 多边形扫描转换

❸ C语言 矩形填充算法

#include <stdio.h>
#include <graphics.h>

typedef struct {
int xmin, xmax, ymin, ymax;
} Rectangle;

void FillRectangle(Rectangle *rect, int color) {
int x = 0, y = 0;
for (y = rect->ymin; y <= rect->ymax; y++)
for (x = rect->xmin; x <= rect->xmax; x++) //这里有个分号,应该去掉。
putpixel(x, y, color);
}/* end of FillRectangle() */

int main() {

//declare our color
int color = 0;

//declare our rectangle
Rectangle *rect = (Rectangle *) malloc(sizeof(Rectangle));

if(NULL == rect )
{
printf("allocation memory failed!\n");
return 1;
}
//input the scope
printf("Enter the x-min:\n");
scanf("%d", &rect->xmin);

printf("Enter the x-max:\n");
scanf("%d", &rect->xmax);

printf("Enter the y-min:\n");
scanf("%d", &rect->ymin);

printf("Enter the y-max:\n");
scanf("%d", &rect->ymax);

//input the color
printf("Enter your color:\n");
scanf("%d", &color);

//call our paint function
FillRectangle(rect, color);

return 0;
}

❹ 填充算法的种子填充算法

种子填充算法又称为边界填充算法。其基本思想是:从多边形区域的一个内点开始,由内向外用给定的颜色画点直到边界为止。如果边界是以一种颜色指定的,则种子填充算法可逐个像素地处理直到遇到边界颜色为止。
种子填充算法常用四连通域和八连通域技术进行填充操作。
从区域内任意一点出发,通过上、下、左、右四个方向到达区域内的任意像素。用这种方法填充的区域就称为四连通域;这种填充方法称为四向连通算法。
从区域内任意一点出发,通过上、下、左、右、左上、左下、右上和右下八个方向到达区域内的任意像素。用这种方法填充的区域就称为八连通域;这种填充方法称为八向连通算法。
一般来说,八向连通算法可以填充四向连通区域,而四向连通算法有时不能填充八向连通区域。例如,八向连通填充算法能够正确填充如图2.4a所示的区域的内部,而四向连通填充算法只能完成如图2.4b的部分填充。
图2.4 四向连通填充算法
a) 连通域及其内点 b) 填充四连通域
四向连通填充算法:
a) 种子像素压入栈中;
b) 如果栈为空,则转e);否则转c);
c) 弹出一个像素,并将该像素置成填充色;并判断该像素相邻的四连通像素是否为边界色或已经置成多边形的填充色,若不是,则将该像素压入栈;
d) 转b);
e) 结束。
四向连通填充方法可以用递归函数实现如下:
算法2.3 四向连通递归填充算法:
void BoundaryFill4(int x, int y, long FilledColor, long BoundaryColor)
{
long CurrentColor;
CurrentColor = GetPixelColor(x,y);
if (CurrentColor != BoundaryColor && CurrentColor != FilledColor)
{
SetColor(FilledColor);
SetPixel (x,y);
BoundaryFill4(x+1, y, FilledColor, BoundaryColor);
BoundaryFill4(x-1, y, FilledColor, BoundaryColor);
BoundaryFill4(x, y+1, FilledColor, BoundaryColor);
BoundaryFill4(x, y-1, FilledColor, BoundaryColor);
}
}
上述算法的优点是非常简单,缺点是需要大量栈空间来存储相邻的点。一个改进的方法就是:通过沿扫描线填充水平像素段,来处理四连通或八连通相邻点,这样就仅仅只需要将每个水平像素段的起始位置压入栈,而不需要将当前位置周围尚未处理的相邻像素都压入栈,从而可以节省大量的栈空间。

❺ 区域填充算法可以填充圆吗

可以的。在圆规则范围之内,由圆心至圆上,任意两条线段(半径)之间,可以用扇形填充并进行计算。

java如何实现填充算法

四向连通递归填充算法:
void BoundaryFill4(int x, int y, long FilledColor, long BoundaryColor)
{
long CurrentColor;
CurrentColor = GetPixelColor(x,y);
if (CurrentColor != BoundaryColor && CurrentColor != FilledColor)
{
SetColor(FilledColor);
SetPixel (x,y);
BoundaryFill4(x+1, y, FilledColor, BoundaryColor);
BoundaryFill4(x-1, y, FilledColor, BoundaryColor);
BoundaryFill4(x, y+1, FilledColor, BoundaryColor);
BoundaryFill4(x, y-1, FilledColor, BoundaryColor);
}
}
该算法的优点是非常简单,缺点是需要大量栈空间来存储相邻的点。

❼ java 计算机图形学 区域填充算法

你可以定义一个类,这个类的作用就是存放你已经存在的图画,在这个类里面实现画图形的方法,然后可以用ArrayList数组实现,最后用个迭代器来实现!!!或者也可以这样考虑,在调用repaint方法的时候系统会自动调用updata方法,你只要覆盖updata方法即可!!!~!~~
哎~~~~你不会查API啊,里面有很多的方法,我也记不住,你自己查一下不就知道拉!!!1

❽ 求八向联通的种子填充算法代码,用C/C++

bool pop(int &x, int &y)
{
if(stackPointer > 0)
{
int p = stack[stackPointer];
x = p / h;
y = p % h;
stackPointer--;
return 1;
}
else
{
return 0;
}
}

bool push(int x, int y)
{
if(stackPointer < stackSize - 1)
{
stackPointer++;
stack[stackPointer] = h * x + y;
return 1;
}
else
{
return 0;
}
}
void floodFill8Stack(int x, int y, int newColor, int oldColor)
{
if(newColor == oldColor) return; //avoid infinite loop
emptyStack();

if(!push(x, y)) return;
while(pop(x, y))
{
screenBuffer[x][y] = newColor;
if(x + 1 < w && screenBuffer[x + 1][y] == oldColor)
{
if(!push(x + 1, y)) return;
}
if(x - 1 >= 0 && screenBuffer[x - 1][y] == oldColor)
{
if(!push(x - 1, y)) return;
}
if(y + 1 < h && screenBuffer[x][y + 1] == oldColor)
{
if(!push(x, y + 1)) return;
}
if(y - 1 >= 0 && screenBuffer[x][y - 1] == oldColor)
{
if(!push(x, y - 1)) return;
}
if(x + 1 < w && y + 1 < h && screenBuffer[x + 1][y + 1] == oldColor)
{
if(!push(x + 1, y + 1)) return;
}
if(x + 1 < w && y - 1 >= 0 && screenBuffer[x + 1][y - 1] == oldColor)
{
if(!push(x + 1, y - 1)) return;
}
if(x - 1 >= 0 && y + 1 < h && screenBuffer[x - 1][y + 1] == oldColor)
{
if(!push(x - 1, y + 1)) return;
}
if(x - 1 >= 0 && y - 1 >= 0 && screenBuffer[x - 1][y - 1] == oldColor)
{
if(!push(x - 1, y - 1)) return;
}
}
}

或者去下面网址看看
http://hi..com/%B1%FE%CF%E6/blog/item/9014b7c3c8b52f100ff4775c.html

热点内容
单片机android 发布:2024-09-20 09:07:24 浏览:759
如何提高三星a7安卓版本 发布:2024-09-20 08:42:35 浏览:659
如何更换服务器网站 发布:2024-09-20 08:42:34 浏览:306
子弹算法 发布:2024-09-20 08:41:55 浏览:284
手机版网易我的世界服务器推荐 发布:2024-09-20 08:41:52 浏览:812
安卓x7怎么边打游戏边看视频 发布:2024-09-20 08:41:52 浏览:158
sql数据库安全 发布:2024-09-20 08:31:32 浏览:89
苹果连接id服务器出错是怎么回事 发布:2024-09-20 08:01:07 浏览:503
编程键是什么 发布:2024-09-20 07:52:47 浏览:655
学考密码重置要求的证件是什么 发布:2024-09-20 07:19:46 浏览:479