我有一张白色背景图片,不适合我应用的黑色背景。
我想让它具有黑色背景,或者反转位图图像中的所有颜色。
我该怎么做?
答案 0 :(得分:0)
获取位图的宽度和高度。将像素存储在数组中,然后迭代每个像素,如果为真,则测试白色(十六进制值),然后将其与黑色值交换。这不是最好的解决方案。为什么不加载黑色位图?
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++;
}
您可以在此处找到颜色的十六进制值