【问题标题】:How to reverse a bitmap color in android with colorfilter?如何使用滤色器在 android 中反转位图颜色?
【发布时间】:2011-07-23 01:58:39
【问题描述】:

我有一张白色背景图片,它不适合我的应用程序的黑色背景。

我想让它有黑色背景,或者反转位图图像中的所有颜色。

我该怎么做?

【问题讨论】:

    标签: android image canvas colors bitmap


    【解决方案1】:

    获取位图的宽度和高度。将像素存储在数组中,然后迭代每个像素,测试白色(十六进制值)是否为真,而不是将其与黑色值交换。这不是最好的解决方案。为什么不直接加载黑色位图?

    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.r);  //example, 
                    int[] pixels = new int[bm.getWidth()*bm.getHeight()];
                    bm.getPixels(pixels, 0, bm.getWidth(),0, 0, bm.getWidth(), bm.getHeight()); //filling the array, this might throw some outofboundaryindex exception for the array, check again.
                    int i = 0;
                   while(i!=bm.getWidth()*bm.getHeight())
                   {
                       if(pixels[i]==hexforblack)
                       {
                           swap it with hex of white
                       }
                       i++;
                   }
    

    在这里您可以找到颜色的十六进制值

    http://www.w3schools.com/html/html_colors.asp

    【讨论】:

      猜你喜欢
      • 2011-06-05
      • 1970-01-01
      • 1970-01-01
      • 2012-08-04
      • 2018-05-07
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 2013-07-18
      相关资源
      最近更新 更多