安卓ApiDemos学习 app/Activity/SetWallpaper

墙纸设置的例子,还涉及一些图片变换的内容

取得当前墙纸

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

效果如下


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值