-1

im doing the project convert the image colour to black and white. what i want is to change the background that it will be black and the image will be white in colour..but mostly of the code that found is changing the image in black and background in white. can anyone know how to change? i already have a code for converting that image to Black and white.

enter image description here

Konrad Krakowiak
  • 11,733
  • 10
  • 53
  • 44

1 Answers1

0

Google is your best friend... http://android-er.blogspot.it/2015/02/invert-bitmap-using-colormatrix.html.

In this example you see that white becomes black and vice/versa.
It also works on all other colors as well.

And it's very fast, because it uses a ColorMatrix, not a pixel by pixel color change, which will wuold require width*hight operations.
It's a single pass!

[EDIT]

I thought you already had the black and white image.
If this is not your case, just use a greyscale ColorMatrix as reported in Lalit Poptani's answer here.

[EDIT 2]

To change brightness and contrast after desaturating (converting to greyscale), try the code found here: Here something to help changing brightness and contrast: http://android.okhelp.cz/bitmap-set-contrast-and-brightness-android/

Community
  • 1
  • 1
Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
  • yes it work. but how to change the colour or contrast of image. i mean..my leaf is orange in colour and after it invert it will be blue. how to make it only black and white.. – user4668241 Mar 16 '15 at 17:03
  • Well I suggested you a solution for AFTER the image is already in BW. So, to convert the image to greyscale, you have to use a different ColorMatrix. I'm updating my answer with that one, also. – Phantômaxx Mar 16 '15 at 17:05
  • sorry for asking again. is there any solution if i want to change the coloured image straight to the inverted one. – user4668241 Mar 16 '15 at 17:24
  • No. You must make 2 steps. Color to grey and then invert. If you want it pure black and white, a 3rd step is seeded, to balace the brightness and contrast and make the greys turn into black or white, given a threshold. – Phantômaxx Mar 16 '15 at 17:30
  • how to given a threshold? – user4668241 Mar 16 '15 at 17:32
  • Added a link to some code to help changing brightness and contrast. – Phantômaxx Mar 16 '15 at 17:47