Android获取当前桌面壁纸
2013-08-29 18:26
549 查看
这段时间项目有需求要获取桌面的壁纸来设成背景,发现网上很多同学都通过WallpaperManager的getDrawable等API来获取,这样的确能获得到壁纸,但是要稍微注意一下。
桌面的壁纸可是很大很大的一张哦,你要直接用来设置成背景,那可是很丑的。所以我们需要稍微处理一下。
大致思路就是把一张壁纸切成几片,当前屏幕对应那片,我们就要那片。上个图:
// 获取壁纸管理器
WallpaperManager wallpaperManager = WallpaperManager
.getInstance(mContext);
// 获取当前壁纸
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
// 将Drawable,转成Bitmap
Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
// 需要详细说明一下,mScreenCount、getCurrentWorkspaceScreen()、mScreenWidth、mScreenHeight分别
//对应于Launcher中的桌面屏幕总数、当前屏幕下标、屏幕宽度、屏幕高度.等下拿Demo的哥们稍微要注意一下
float step = 0;
// 计算出屏幕的偏移量
step = (bm.getWidth() - LauncherPreferenceModel.mScreenWidth)
/ (LauncherPreferenceModel.mScreenCount - 1);
// 截取相应屏幕的Bitmap
Bitmap pbm = Bitmap.createBitmap(bm, (int) (mLauncher
.getCurrentWorkspaceScreen() * step), 0,
(int) (LauncherPreferenceModel.mScreenWidth),
(int) (LauncherPreferenceModel.mScreenHeight));
// 设置 背景
layout.setBackgroundDrawable(new BitmapDrawable(pbm));
桌面的壁纸可是很大很大的一张哦,你要直接用来设置成背景,那可是很丑的。所以我们需要稍微处理一下。
大致思路就是把一张壁纸切成几片,当前屏幕对应那片,我们就要那片。上个图:
// 获取壁纸管理器
WallpaperManager wallpaperManager = WallpaperManager
.getInstance(mContext);
// 获取当前壁纸
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
// 将Drawable,转成Bitmap
Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
// 需要详细说明一下,mScreenCount、getCurrentWorkspaceScreen()、mScreenWidth、mScreenHeight分别
//对应于Launcher中的桌面屏幕总数、当前屏幕下标、屏幕宽度、屏幕高度.等下拿Demo的哥们稍微要注意一下
float step = 0;
// 计算出屏幕的偏移量
step = (bm.getWidth() - LauncherPreferenceModel.mScreenWidth)
/ (LauncherPreferenceModel.mScreenCount - 1);
// 截取相应屏幕的Bitmap
Bitmap pbm = Bitmap.createBitmap(bm, (int) (mLauncher
.getCurrentWorkspaceScreen() * step), 0,
(int) (LauncherPreferenceModel.mScreenWidth),
(int) (LauncherPreferenceModel.mScreenHeight));
// 设置 背景
layout.setBackgroundDrawable(new BitmapDrawable(pbm));
相关文章推荐
- Android获取当前桌面壁纸
- Android获取当前桌面壁纸
- Android获取当前桌面壁纸
- Android 获取当前壁纸
- C#获取当前电脑桌面的壁纸,并设置成窗体背景图
- android 调用系统相册选取照片或者打开相机拍照获取图片,返回时回到手机桌面,然后才会跳转到当前activity
- Android获取当前默认桌面
- Android之获取默认桌面、默认输入法、默认动态壁纸的接口
- android 调用系统相册选取照片或者打开相机拍照获取图片,返回时回到手机桌面,然后才会跳转到当前activity
- Android中LocationManager的简单使用,获取当前位置(转http://www.javaeye.com/topic/363950)
- Android 获取当前系统语言及地区,并更改语言
- java/android中获取当前日期的方法
- android 获取当前时间的几种方式,总结
- android 获取当前设备的ip地址 mac地址 设备号 手机号 运营商信息
- Android获取当前系统语言
- Android获取当前应用的版本号
- android 如何获取一个程序的当前版本号
- Android获取屏幕分辨率和大小与设置壁纸、动态壁纸
- 获取当前使用Android的用户的Id
- android UiAutomator获取当前页面某类控件个数的方法