Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android应用中的洪水填充_Android_Canvas_Bitmap_Antialiasing - Fatal编程技术网

Android应用中的洪水填充

Android应用中的洪水填充,android,canvas,bitmap,antialiasing,Android,Canvas,Bitmap,Antialiasing,我正在使用画布创建一个绘图应用程序。我使用下面的代码进行整体填充,但在低或中等dpi设备上,图像的某些部分仍然未填充,即在非均匀形状的边缘。有些点在不均匀的边上仍然未填充 public class FloodFill extends AsyncTask<Void, Void, Void> { private int width; private int height; private int target;

我正在使用画布创建一个绘图应用程序。我使用下面的代码进行整体填充,但在低或中等dpi设备上,图像的某些部分仍然未填充,即在非均匀形状的边缘。有些点在不均匀的边上仍然未填充

    public class FloodFill extends AsyncTask<Void, Void, Void>
    {

        private int width;
        private int height;
        private int target;
        private int replacement;
        private Point node;
        private ProgressDialog progress;

        public FloodFill(Bitmap image, Point node2, int targetColor, int replacementColor)
        {
            flood = Bitmap.createBitmap(image);
            image.recycle();
            this.width = flood.getWidth();
            this.height = flood.getHeight();
            this.target = targetColor;
            this.replacement = replacementColor;
            this.node = node2;
        }

        @Override
        protected void onPreExecute()
        {
            super.onPreExecute();
            progress = new ProgressDialog(MainActivity.this);
            progress.setMessage("Filling");
            progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progress.setIndeterminate(true);
            progress.setCancelable(false);
            progress.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            if (target != replacement)
            {
                Queue<Point> queue = new LinkedList<Point>();
                do
                {
                    int x = node.x;
                    int y = node.y;
                    while (x > 0 && flood.getPixel(x - 1, y) == target)
                    {
                        x--;
                    }                        
                    boolean spanUp = false;
                    boolean spanDown = false;
                    while (x < width && flood.getPixel(x, y) == target)
                    {
                        flood.setPixel(x, y, replacement);
                        if (!spanUp && y > 0 && flood.getPixel(x, y - 1) == target)
                        {
                            queue.add(new Point(x, y - 1));
                            spanUp = true;
                        }
                        else if (spanUp && y > 0 && flood.getPixel(x, y - 1) != target)
                        {
                            spanUp = false;
                        }
                        if (!spanDown && y < height - 1 && flood.getPixel(x, y + 1) == target)
                        {
                            queue.add(new Point(x, y + 1));
                            spanDown = true;
                        }
                        else if (spanDown && y < height - 1 && flood.getPixel(x, y + 1) != target)
                        {
                            spanDown = false;
                        }
                        x++;
                    }
                } while ((node = queue.poll()) != null);
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            progress.dismiss();
            invalidate();
        }
    }
我需要关于这方面的帮助,我是否应该尝试实现另一个算法,如果是,那么哪一个或我应该尝试在洪水填充后的图像上实现抗锯齿

提前谢谢