【问题标题】:Android - how to place color on Bitmap?Android - 如何在位图上放置颜色?
【发布时间】:2014-01-16 03:08:56
【问题描述】:

我有一张图片 (http://imgur.com/lIfzpWB.png),我通过 Bitmap.decodeFile(path); 打开它。 但是我可以用我的位图做什么来得到这张图片(http://imgur.com/GHltevM.png)呢? 我想我需要在位图上应用某种颜色蒙版。我该怎么做?

UPD我使用以下代码来实现我的结果:


image.setImageDrawable(convert(original, 0x7F00FF00));



public BitmapDrawable convert(Bitmap src, int color) {
    BitmapDrawable temp = new BitmapDrawable(src);
    temp.setColorFilter(new LightingColorFilter(0, color));
    return temp;
}

UPD 我完成了我的代码!我刚刚将new LightingColorFilter(0, color) 替换为new LightingColorFilter(color, 0)。谢谢大家的帮助!

【问题讨论】:

    标签: java android bitmap


    【解决方案1】:

    试试这样的。

    Bitmap bitmap = Bitmap.decodeFile(path);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setColorFilter(new LightingColorFilter(0, 0x005500));
    canvas.drawPaint(paint);
    

    这应该可以满足您的要求(我还没有尝试过),尽管您可能需要调整 lightingColorFilter 的值才能达到您想要达到的效果。

    【讨论】:

      【解决方案2】:

      您需要移除绿色通道。

      您可以将文件作为缓冲图像打开为名为 `imagè 的变量,然后使用以下代码:

          for(int i=0;i<image.getWidth();i++)
           for(int j=0;j<image.getHeight();j++){
              Color c=new Color(image.getRGB(i,j));
               int pixel=c.getRed()<<16|c.getBlue();
               image.setRGB(pixel);
           }
      

      生成的 `image 将是您没有绿色通道的图像。

      【讨论】:

        猜你喜欢
        • 2013-08-22
        • 1970-01-01
        • 2021-07-06
        • 1970-01-01
        • 2011-08-07
        • 1970-01-01
        • 2013-11-15
        • 1970-01-01
        • 2018-01-21
        相关资源
        最近更新 更多