Actually My requirement is to get the icon color of any app installed in my device. I want to show an lock screen of that color. So how can I get the color code of any icon programmatically?
if you want to get the all color's RGB value from a single icon--
Bitmap bitmap;
// create the bitmap from your obtained image
int pixel = bitmap.getPixel(x,y); // x,y is the desired position of the target pixel, for full imag, you have to do the same thing in a loop
int red = Color.red(pixel);
int green = Color.green(pixel);
int blue = Color.blue(pixel);
The int values returned are your standard 0 - 255. You can modify this code and get a color from anywhere, providing you can turn it into a bitmap. And you can use the Color API to get an actual RGB value like this:
int rgb = Color.rgb(red, blue, green); // rgb value of a single pixel,
Now, in order to get the all the pixels at once, you can use Bitmap.getPixels()
int[] allPixels = new int[bitmap.getWidth()*bitmap.getHeight()];
bitmap.getPixels(allPixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With