墙纸设置的例子,还涉及一些图片变换的内容
取得当前墙纸
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
将墙纸设置到imageview上
imageView.setDrawingCacheEnabled(true);
imageView.setImageDrawable(wallpaperDrawable);
因为要对图片进行一些处理,所以打开了catch
imageView.setDrawingCacheEnabled(true)
点击Randomize按钮时,会随机生成一个数字,然后从预定义的数据中取出颜色
int mColor = (int) Math.floor(Math.random() * mColors.length);
然后将颜色覆盖在图片上,只允许某些颜色通过。
wallpaperDrawable.setColorFilter(mColors[mColor], PorterDuff.Mode.MULTIPLY);
mColors是一个数据,预先定义了一些颜色
final static private int[] mColors =
{Color.BLUE, Color.GREEN, Color.RED, Color.LTGRAY, Color.MAGENTA, Color.CYAN,
Color.YELLOW, Color.WHITE};
用户点击 Set Wallpaper按钮后,将新墙纸设置到系统中
wallpaperManager.setBitmap(imageView.getDrawingCache());
效果如下