Reputation: 39
I have a simple image in my project for android 2.3.3 that i want to know the color of the first pixel and replace every pixel with that color to the background color.... I tried everything like iterating the pixels and setting the color of the pixels and I get nothing...For example,with that picture:
https://www.dropbox.com/s/e9dcq72c9u5o3op/img2.jpg
I want to get a result like that: https://www.dropbox.com/s/r9zox7zueekq2xe/img3.jpg
I'm a very new developer for Android, and because of that sorry for my NAIF question!
Upvotes: 3
Views: 3845
Reputation: 13855
Simply use ColorFilter to achieve this. It will replace one colour with another. Working example:
Paint pnt = new Paint();
Bitmap myBit = BitmapFactory.decodeFile(pathName);
Canvas myCanvas = new Canvas(myBit );
int myColor = myBit.getPixel(0, 0);
// Set the colour to replace.
ColorFilter filter = new LightingColorFilter(myColor, Color.WHITE );
pnt.setColorFilter(filter);
// Draw onto new bitmap. result Bitmap is newBit
myCanvas.drawBitmap(myBit,0,0, pnt);
Upvotes: 4