2010-11-16 9 views
6

No puedo encontrar una implementación de algoritmo floodfill para Android.Algoritmo Floodfill en Android

Alguna idea de si una API floodfill está disponible en Android, y si no, ¿hay alguna otra alternativa?

+0

No creo que pueda obtener una matriz de píxeles de un mapa de bits y colores alternativos usted mismo – schwiz

+0

¿Está hablando de edición de imágenes? ¿O solo un algoritmo genérico para una matriz multidimensional? –

+0

@alien ¿alguna vez encontró una solución a esto? Si es así, ¿cree que podría darme el código fuente o un ejemplo? – Hades

Respuesta

2

¿Tiene alguna definición de la forma?

Si es así, eche un vistazo a Canvas docs. Puede llenar una región definiendo un área de clip y luego llamando a canvas.drawColor.

ejemplo áspera:

Rect r = new Rect(0,0,300,300); 
    canvas.clipRect(r); // see also clipRegion 
    canvas.drawColor(Color.RED); 

Hay varias funciones de clips, por lo que debe ser capaz de construir lo que estamos tratando de llenar.

Por otro lado, si desea saturar una región en un mapa de bits cargado, entonces no sé.

2

FloodFill en Android

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>(); 
    do { 
     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); 
} 
} 
} 

Usted debe utilizar un AsyncTask utilizar el algoritmo FloodFill. Usar el mismo en el hilo principal causó un error de memoria. Incluso si uso Algoritmo Floofill algún día, llenar una gran área lleva más tiempo y hace que la aplicación deje de responder a tiempo.

Fill the complete canvas but keep the bound fill area as it is like circle, rectangle. Este enlace podría resolver su problema

+0

Wow nice working ..... +1 por gran respuesta –