当位图适合创建缩放位图的屏幕时,floodfill android不工作

当位图适合创建缩放位图的屏幕时,floodfill android不工作,android,bitmap,scale,flood-fill,Android,Bitmap,Scale,Flood Fill,在我的应用程序中,我使用泛光填充来填充位图的颜色部分。一切正常,但我用createscaledbitmap创建位图,它不工作。请推荐我 我的代码如下 我让floodfill在异步任务中运行 @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { ca

在我的应用程序中,我使用泛光填充来填充位图的颜色部分。一切正常,但我用createscaledbitmap创建位图,它不工作。请推荐我

我的代码如下

我让floodfill在异步任务中运行

 @Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:

        p1.x = (int) x;
        p1.y = (int) y;
        final int sourceColor = resultBmp.getPixel((int) x, (int) y);
        final int targetColor = paint.getColor();
        new TheTask(resultBmp, p1, sourceColor, targetColor).execute();
        invalidate();
    }
    return true;
}

public void clear() {
    path.reset();
    invalidate();
}

public int getCurrentPaintColor() {
    return paint.getColor();
}

class TheTask extends AsyncTask<Void, Integer, Void> {

    Bitmap bmp;
    Point pt;
    int replacementColor, targetColor;

    public TheTask(Bitmap bm, Point p, int sc, int tc) {
        this.bmp = bm;
        this.pt = p;
        this.replacementColor = tc;
        this.targetColor = sc;
        pd.setMessage("Filling....");
        pd.show();
    }

    @Override
    protected void onPreExecute() {
        pd.show();

    }

    @Override
    protected void onProgressUpdate(Integer... values) {

    }

    @Override
    protected Void doInBackground(Void... params) {
        FloodFill f = new FloodFill();
        f.floodFill(bmp, pt, targetColor, replacementColor);
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        pd.dismiss();
        invalidate();
    }
}
}

请建议我

泛光填充方法是采用每个像素并在线程中更改其颜色,因此,我不是使用创建缩放位图来增加大小,而是针对不同的屏幕大小使用单独的位图。这是一个繁琐的过程,但根据我的研究,没有其他方法。

请看这个问题,你给出的链接与洪水填充完全不同。Flood fill在windows paint app中用作油漆瓶。请参阅此以了解有关洪水填充的更多信息
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);
    }
}
}
  @Override
protected void onDraw(Canvas canvas) {
    this.canvas = canvas;

    int w = mBitmap.getWidth();
    int h = mBitmap.getHeight();

   resultBmp = null;



    int widthofBitMap = screenWidth;
    int heightofBitMap = widthofBitMap * h / w;

    resultBmp = Bitmap.createScaledBitmap(mBitmap, widthofBitMap, heightofBitMap, true);

    canvas.drawBitmap(resultBmp, 0, 0, paint);
  //if i create only bitmap without scaling it works fine.
 // for ex
 //canvas.drawBitmap(mBitmap,0,0,paint); works fine.

}