FloodFill在iphone [英] FloodFill in iphone

查看:136
本文介绍了FloodFill在iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iphone开发的新手。我想在iphone中使用FloodFill算法创建一个应用程序。我没有FloodFill的任何想法。解释FloodFill算法的目的。如果你给一个示例应用程序FloodFill(iphone)意味着我真的很高兴,因为我从早上探索FloodFill,但没有找到..



MyTask是,



我想用颜色填充图片,一部分。 ie ..如果我选择一种颜色,点击图像的特定区域意味着它用选定的颜色着色。



请帮助我做这个。



编辑:我无法为iphone的floodfill算法实现编写代码。



帮助我...

解决方案

这是一个递归算法,意味着它调用自己来完成整个过程的较小部分。 / p>

灌水将从一个像素开始。然后它将检查四个相邻的像素(上,下,左,右)。对于那些与我们开始的颜色相同的那四个像素,它将调用从该像素开始的另一个泛光填充。



想象一个小图片。是一种颜色,X是另一种颜色。数字仅供参考,因此7,0是右上角。 (忽略红色/黑色语法高亮!)

  01234567 
0 ........
1.XXXX ...
2.X..X ...
3.X ... X ..
4.XXX..X。
5 ... X..X
6 ... XXX ..
7 ........

现在想象你在3,3开始填水。它会将3,3改为新颜色。
然后它会检查,下,左,右。
对于up(3,2),颜色是相同的(点),所以它会从那里开始另一个洪水填充。
对于down(3,4),颜色不同,因此此分支将停止。
左,(2,3)和右(4,3)也是相同的(点),因此从那里开始更多的洪水分支。



假设新颜色为O,因此我们现在有了这个:

  01234567 
0 ... .....
1.XXXX ...
2.X.OX ...
3.XOOOX ..
4.XXX..X。
5 ... X..X。
6 ... XXX ..
7 ........

up分支从(3,2)开始新的洪水填充。
从这里,up是X,所以停止。右边是X,所以停止,下来是O,所以停止,但左(2,2)是相同的(点),所以它从那里开始一个新的洪水填充。



类似地,从原始洪水填充的右分支从(4,3)开始。它可以使用的唯一分支是下(4,4)。现在我们有了:

  01234567 
0 ........
1.XXXX ...
2.XOOX ...
3.XOOOX ..
4.XXXO.X.
5 ... X..X。
6 ... XXX ..
7 ........

因此,通过向右和向下分支,洪水从(4,4)继续。那两个分支之一然后将分支到(5,5)。



这是我的午餐时间:)


I'm very new to iphone development.I want to create a application using FloodFill algorithm in iphone.I'm not having any idea of FloodFill.Please Explain me the purpose of FloodFill algorithm.If you give a sample application for FloodFill(iphone)means i'm really,really happy..Because i'm exploring about FloodFill since morning but,nothing i'm found..

MyTask is,

I want to fill the image with color as part by part. ie..,If i'm choosing one color and click on the particular area of the image means it gets colored with selected color.

Please help me to do this.

Edit:I am not able to write a code for floodfill algorithm implementation for iphone.

please any one help me...

解决方案

It's a recursive algorithm, meaning that it calls itself to accomplish smaller parts of the whole process.

Flood fill will start at one pixel. Then it will check the four adjacent pixels (up, down, left, right). For any of those four pixels that are the same colour as the one we started with, it will call another flood fill starting from that pixel.

Imagine a small picture where . is one colour, and X is another colour. The numbers are just there for reference, so 7,0 is the top right. (Ignore the red / black syntax hilighting!)

 01234567
0........
1.XXXX...
2.X..X...
3.X...X..
4.XXX..X.
5...X..X.
6...XXX..
7........

Now imagine you start a flood fill at 3,3. It will change 3,3 to the new colour. It will then check up,down,left,right. For up (3,2), the colour there is the same (a dot), so it will start another flood fill from there. For down (3,4), the colour is different, so this branch will stop. Left, (2,3), and right (4,3) are also the same (a dot), so more branches of flood fill start from there.

Let's say that new colour is O, so we now have this:

 01234567
0........
1.XXXX...
2.X.OX...
3.XOOOX..
4.XXX..X.
5...X..X.
6...XXX..
7........

The "up" branch started a new flood fill from (3,2). From here, up is X, so that stops. Right is X, so that stops, down is O, so that stops, but left (2,2) is the same (a dot), so it starts a new flood fill from there.

Similarly, the "right" branch from the original flood fill began from (4,3). The only branch it can use is down (4,4). Now we have this:

 01234567
0........
1.XXXX...
2.XOOX...
3.XOOOX..
4.XXXO.X.
5...X..X.
6...XXX..
7........

And so the flood fill continues from (4,4), by branching right and down. One of those two branches will then branch into (5,5). By that time, there will be no further possible branches.

And that is my lunchtime filled :)

这篇关于FloodFill在iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆