【发布时间】:2011-07-23 01:58:39
【问题描述】:
我有一张白色背景图片,它不适合我的应用程序的黑色背景。
我想让它有黑色背景,或者反转位图图像中的所有颜色。
我该怎么做?
【问题讨论】:
标签: android image canvas colors bitmap
我有一张白色背景图片,它不适合我的应用程序的黑色背景。
我想让它有黑色背景,或者反转位图图像中的所有颜色。
我该怎么做?
【问题讨论】:
标签: android image canvas colors bitmap
获取位图的宽度和高度。将像素存储在数组中,然后迭代每个像素,测试白色(十六进制值)是否为真,而不是将其与黑色值交换。这不是最好的解决方案。为什么不直接加载黑色位图?
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++;
}
在这里您可以找到颜色的十六进制值
【讨论】: