i Want to get Most prominent color Code like(Black,White, Blue etc etc)from bitmap without using Palette Api Android..Please Help
Asked
Active
Viewed 273 times
0
-
1Palette is designed specifically for this case. Why are you looking for an alternative? – Henry Oct 21 '15 at 19:53
-
because i am not using v7 support library in my project... i dont want to use it right now – Mustanser Iqbal Oct 21 '15 at 19:56
2 Answers
0
OK, so what you need to do is essentially blur the bitmap and then pick out the pixel color. You can blur is simply by scaling it down to a small size and then enlarging it to a larger one (Bitmap.createScaledBitmap()
). This will pixelate your bitmap. Then you obtain the color of the pixels (Bitmap.getPixels(x,y)
).
Experiment with the scaling so that the final bitmap contains fewer colors as pixels.

Henry
- 17,490
- 7
- 63
- 98
-
i can get the color of the pixels... but how can i know that which color is most prominent than other colors in bitmap? – Mustanser Iqbal Oct 21 '15 at 20:10
-
When you blur the image, only the prominent colors shows up. If a color appears only 1% in your bitmap, on blurring it, that color is lost. As I mentioned you need to experiment with blurring the bitmap. – Henry Oct 21 '15 at 20:12
-
ok let me try then i'll let you know when i done with it.. thanks for hint – Mustanser Iqbal Oct 21 '15 at 20:26
0
You want to get shades image? In any case, you need something like this:
import android.graphics.Color;
int reds = 0;
int blues = 0;
int greens = 0;
int[] pixels = new int[myBitmap.getHeight()*myBitmap.getWidth()];
myBitmap.getPixels(pixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());
for (int i=0; i<pixels.length; i++) {
int red = Color.red(colour);
int blue = Color.blue(colour);
int green = Color.green(colour);
/* Or it
r = (pix[i]) >> 16 & 0xff;
g = (pix[i]) >> 8 & 0xff;
b = (pix[i]) & 0xff;*/
//int alpha = Color.alpha(colour);
if (red >= blue && red >= green) reds++;
if (blue >= red && blue >= green) blues++;
if (green >= blue && green >= red) greens++;
}

user2413972
- 1,355
- 2
- 9
- 25
-
i managed to get color like this but Can you tell me how can i remove a specific color from bitmap? Although i managed to remove the color but it is not removing completely? – Mustanser Iqbal Oct 21 '15 at 21:10
-
You need to get the color tones. But dude, you're asking have more of information without even+. Read it: http://stackoverflow.com/questions/9018016/how-to-compare-two-colors – user2413972 Oct 21 '15 at 21:57