位图中的红色更换黑色 [英] Replace black color in bitmap with red

查看:187
本文介绍了位图中的红色更换黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能代替黑色位图用红色(或其他任何颜色)编程的机器人(忽略透明度)?我可以用一种颜色替换白色的位图了,但是它并不会自动加黑的工作。 感谢您的帮助。

How can I replace the black color in a bitmap with red (or any other color) programmatically in Android (ignoring transparency)? I can replace the white color in the bitmap with a color already but it somehow does not work with black. Thanks for help.

推荐答案

获取位图使用这一切的像素:

Get all the pixels in the bitmap using this:

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.lenght; i++)
{
    if(allpixels[i] == Color.BLACK)
    {
        allpixels[i] = Color.RED;
    }
}

myBitmap.setPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());

这篇关于位图中的红色更换黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆