android - 如何在特定区域填充图像中的颜色?

标签 android image image-processing bitmap paint

我想为基于 Paint 的应用程序填充白色区域的颜色 所以请给我关于如何完成这项工作的建议..

enter image description here

最佳答案

我找到了使用洪水填充算法的解决方案

private void FloodFill(Bitmap bmp, Point pt, int targetColor, int replacementColor){
Queue<Point> q = new LinkedList<Point>();
q.add(pt);
while (q.size() > 0) {
    Point n = q.poll();
    if (bmp.getPixel(n.x, n.y) != targetColor)
        continue;

    Point w = n, e = new Point(n.x + 1, n.y);
    while ((w.x > 0) && (bmp.getPixel(w.x, w.y) == targetColor)) {
        bmp.setPixel(w.x, w.y, replacementColor);
        if ((w.y > 0) && (bmp.getPixel(w.x, w.y - 1) == targetColor))
            q.add(new Point(w.x, w.y - 1));
        if ((w.y < bmp.getHeight() - 1)
                && (bmp.getPixel(w.x, w.y + 1) == targetColor))
            q.add(new Point(w.x, w.y + 1));
        w.x--;
    }
    while ((e.x < bmp.getWidth() - 1)
            && (bmp.getPixel(e.x, e.y) == targetColor)) {
        bmp.setPixel(e.x, e.y, replacementColor);

        if ((e.y > 0) && (bmp.getPixel(e.x, e.y - 1) == targetColor))
            q.add(new Point(e.x, e.y - 1));
        if ((e.y < bmp.getHeight() - 1)
                && (bmp.getPixel(e.x, e.y + 1) == targetColor))
            q.add(new Point(e.x, e.y + 1));
        e.x++;
    }
}}

flood in android:

查看此 FloodFill

关于android - 如何在特定区域填充图像中的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8801047/

相关文章:

android - 使用 Nodejs + SocketIO 时丢弃传输错误

c# - Geo-Tiff 到 ECW 转换?

android - 从 themes.xml 更改 TopAppBar 背景颜色

android - Python - stdout 的 Android logcat 输出到 textview 然后保存到 .txt 文件错误

image - 心理视觉图像相似度算法/库

c# - 文件去斑 - OCR

algorithm - 如何将点分组在同一条曲线 "row"中?

java - 使用 If 语句确定图像的 ColorModel?

android - 在不扩展 PreferenceActivity 的情况下加载 preferences.xml

linux - 使用 Linux (Debian) 获取图像中像素的颜色