user3936734
user3936734

Reputation:

How to get the app icon color code programmaticallyin android?

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?

Upvotes: 3

Views: 1008

Answers (2)

Amit K. Saha
Amit K. Saha

Reputation: 5951

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());

Upvotes: 3

Lars Nielsen
Lars Nielsen

Reputation: 150

I don't know what you mean by getting the icon color, since the icon is an image, but you can fetch the icon of an known application like this: https://stackoverflow.com/a/13609127/3965178

And you can fetch all installed application like this: How to get all apps installed on android phone

Hope this will help you a bit.

Upvotes: 0

Related Questions