【问题标题】:How to perform color blending in touch portion of the image in android如何在android中图像的触摸部分执行颜色混合
【发布时间】:2012-09-14 10:41:35
【问题描述】:

我正在尝试更改触摸部分图像的颜色。我尝试了以下两种方法,

1)

  mPaint = new Paint();  
  mPaint.setColor(Color.RED);  
  mPaint.setStyle( Paint.Style.STROKE );  
  mPaint.setStrokeJoin( Paint.Join.ROUND );  
  mPaint.setStrokeCap( Paint.Cap.ROUND );  
  mPaint.setStrokeWidth( SettingsActivity.brushsize + 5);  
  mPaint.setFilterBitmap( false );  

结果:在这种情况下没有发生混合,颜色完全覆盖图像。

2)

  mPaint = new Paint();  
  ColorFilter filter = new LightingColorFilter(Color.RED, 1);  
  mPaint.setColorFilter(filter);  
  mPaint.setStyle( Paint.Style.STROKE );  
  mPaint.setStrokeJoin( Paint.Join.ROUND );  
  mPaint.setStrokeCap( Paint.Cap.ROUND );  
  mPaint.setStrokeWidth(  5);  
  mPaint.setFilterBitmap( false );  

结果:我一直在使用观察黑色。

如何在图像的触摸部分进行颜色混合?

【问题讨论】:

标签: android image colors blending


【解决方案1】:

使用洪水填充算法。 看看这段代码:

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++;
    }
}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多