OK、この機能を提供する単一の API はないと言わざるを得ませんでした。ユーザーは 2 つのビットマップを合成する必要があります。1 つは壁紙部分、もう 1 つはランチャーのデスクトップ ビューです。通常、ランチャーは壁紙を複数の画面に拡張するため、壁紙の可視部分を取得する必要があります。
以下は私が行う方法です:
//get wallpaper's visible part
//@param screenCount how many screens launcher has
//@param screenCurrent current screen index
Bitmap wallpaper =
((BitmapDrawable) WallpaperManager.getInstance(context).getDrawable()).getBitmap();
float step = 0;
step = (wallpaper.getWidth() - w) / (screenCount - 1);
Bitmap wallpaperCurrent =
Bitmap.createBitmap(wallpaper, (int)(screenCurrent * step), 0, w, h);
//get launcher's visible view bitmap
View decorview = context.getWindow().getDecorView();
decorview.buildDrawingCache();
Bitmap desktopBitmap = decorview.getDrawingCache();
//compound bitmaps
Bitmap compoundBitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(compoundBitmap);
canvas.drawBitmap(wallpaperCurrent, 0, 0, null);
canvas.drawBitmap(desktopBitmap, 0, 0, null);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
// return compoundBitmap