How to implement the flood-fill algorithm in android? -


how implement flood-fill algorithm in android.but code written in c language.could implement algorithm in android.is there open source code available or website tutorial link

algorithm flood fill simple recursive one.

//initialize , j place start floodfill(int arr[][], target_color, replace_color) {     if(arr[i][j] == replace_color)         return;     replace(target_color, replace_color);     floodfill(int[i+1][j], target_color, replace_color);     floodfill(int[i][j+1], target_color, replace_color);     floodfill(int[i-1][j], target_color, replace_color);     floodfill(int[i][j-1], target_color, replace_color); } 

flood fill using queue. use asynctask flood fill.

parameters

  1. bitamp filled
  2. point user touches (x,y cordinates)
  3. color of pixel use touches
  4. color replaced.

    public class floodfill {  public void floodfill(bitmap  image, point node, int targetcolor,     int replacementcolor) { int width = image.getwidth(); int height = image.getheight(); int target = targetcolor; int replacement = replacementcolor; if (target != replacement) {     queue<point> queue = new linkedlist<point>();     {         int x = node.x;         int y = node.y;         while (x > 0 && image.getpixel(x - 1, y) == target) {             x--;         }         boolean spanup = false;         boolean spandown = false;         while (x < width && image.getpixel(x, y) == target) {             image.setpixel(x, y, replacement);             if (!spanup && y > 0 && image.getpixel(x, y - 1) == target) {                 queue.add(new point(x, y - 1));                 spanup = true;             } else if (spanup && y > 0                     && image.getpixel(x, y - 1) != target) {                 spanup = false;             }             if (!spandown && y < height - 1                     && image.getpixel(x, y + 1) == target) {                 queue.add(new point(x, y + 1));                 spandown = true;             } else if (spandown && y < height - 1                     && image.getpixel(x, y + 1) != target) {                 spandown = false;             }             x++;         }     } while ((node = queue.poll()) != null); }   }      } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -

delphi - How to convert bitmaps to video? -