我找到的JAVA原生代码:
//获取布局
LinearLayout layout = (LinearLayout) this.findViewById(R.id.ll);
//获取WallpaperManager 壁纸管理器
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); // 获取壁纸管理器
// 获取当前壁纸
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
//将Drawable,转成Bitmap
Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
float step = 0;
//计算出屏幕的偏移量
step = (bm.getWidth() - 480) / (7 - 1);
//截取相应屏幕的Bitmap
Bitmap pbm = Bitmap.createBitmap(bm, (int) (5 * step), 0, 480, 854);
//设置 背景
layout.setBackgroundDrawable(new BitmapDrawable(pbm));
用NJS转换,到这一行卡住了:Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
求助!这一行有个强制转换,该如何转换啊?
liyangDXL100 (作者)
我需要获取壁纸不是修改壁纸
2022-10-11 14:27