0

I want to set my whole bitmap to grayscale, but I want to keep one color, red or blue or green or any color the user likes? Is this possible with a colormatrix? Here's a link, that's what I want to do but in android. How can I convert an RGB image to grayscale but keep one color?

Thank you very much.

Community
  • 1
  • 1
RoterBaron
  • 103
  • 2
  • 10

1 Answers1

1

Try this:

ImageView imageView;
Bitmap photo,photo1;
photo1 = Bitmap.createBitmap(photo.getWidth(),photo.getHeight(),photo.getConfig());

for(int i=0;i<photo.getWidth();i++)
{
    for(int j=0;j<photo.getHeight();j++){
        int p=photo.getPixel(i,j);
        int r= Color.red(p);
        int g=Color.green(p);
        int b=Color.blue(p);
        int alpha=Color.alpha(p);
        r=0;
        g=g+150;
        b=0;
        alpha=0;
        photo1.setPixel(i,j, Color.argb(Color.alpha(p),r,g,b));
    }
}
imageView.setImageBitmap(photo1)
rghome
  • 8,529
  • 8
  • 43
  • 62
SEEMA
  • 11
  • 1