Reputation: 683
I was going through Android : Converting color image to grayscale and other similar answers, when I doubted whether it's possible to grayscale a coloured "background image" i.e., image set using android:background=""
. Is it possible? If yes, how?
I have not got the answer even after several hours of extensive googling.
EDIT: I have found a hack for the problem, but it does not solve the problem completely. I have used
android:backgroundTint="#999999"
android:backgroundTintMode="multiply"
along with my code to set the background image.
Upvotes: 2
Views: 1579
Reputation: 1691
Use an ImageView in your layout instead of trying to set the background to a drawable and then use this code to programmatically color the image to grayscale.
final ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
mImageView.setColorFilter(filter);
If you need help using an ImageView instead of background, please post your layout xml and java code for this scene.
Upvotes: 2