如何在 Android 中以编程方式将位图中的黑色替换为红色(或任何其他颜色)(忽略透明度)?我已经可以用一种颜色替换位图中的白色,但它在某种程度上不适用于黑色。 感谢您的帮助。
最佳答案
使用以下方法获取位图中的所有像素:
int [] allpixels = new int [myBitmap.getHeight() * myBitmap.getWidth()];
myBitmap.getPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());
for(int i = 0; i < allpixels.length; i++)
{
if(allpixels[i] == Color.BLACK)
{
allpixels[i] = Color.RED;
}
}
myBitmap.setPixels(allpixels,0,myBitmap.getWidth(),0, 0, myBitmap.getWidth(),myBitmap.getHeight());
关于android - 用红色替换位图中的黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7237915/