3

How can I find the (Average) color of the current wallpaper and set that color to a layout on my widget?

An example of what I'm trying to do:

enter image description here

This is a setting on AccuWeather:

enter image description here

Muhammad Ali
  • 3,478
  • 5
  • 19
  • 30
  • 2
    1>https://chris.banes.me/2014/07/04/palette-preview/ 2>http://willowtreeapps.com/blog/palette-the-new-api-for-android/. maybe this can help. – Anirudh Sharma Nov 10 '15 at 05:07
  • Fastest method (calculates 1 pixel only after averaging a 1x1 px copy of the bitmap): http://stackoverflow.com/a/29185394/2649012 – Phantômaxx Nov 10 '15 at 08:07

4 Answers4

2

You can use WallpaperManager.getWallpaperColors that was added in API 27

Vladimir Berezkin
  • 3,580
  • 4
  • 27
  • 33
0

First you have to get current wallpaper and convert it to bitmap like

final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
Bitmap bitmap = ((BitmapDrawable)wallpaperDrawable).getBitmap();

After that use this link to get dominant color of an image.

Community
  • 1
  • 1
-1

You can use Bitmap to find the pixels and you can compare the values to find the average pixels.

For ex-

ImageView imageView = ((ImageView)v);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(x,y);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);

There are many ways you can do this..

Please tell more information what do you want to do?

What you can do is-

get the wallpaper using WallpaperMAnager.

Convert it to Bitmap.

Get all the pixels Above techniques might help you.

Calculate the average using pixel arrays.

Using the average make a color and set your wallpaper to the calculated average color.

RajSharma
  • 1,941
  • 3
  • 21
  • 34
  • Sorry for not clarifying properly. I would want to change the background color of the layout inside my widget whenever the wallpaper is changed on the device. This color would match the color of the wallpaper. – Muhammad Ali Nov 10 '15 at 05:31
-1

I think you can use this to get the wallpaper and transfer it to Bitmap:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
panda
  • 560
  • 2
  • 10