是否可以使用视图后面的视图获取绘图缓存?例如,我有一个半透明的视图,我可以看到它背后的视图。那么,我可以在后面的视图可见的情况下获得该视图的绘图缓存吗?
我将视图添加到 WM 的代码:
final View screenshotView = new View(this) {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (!changed) {
buildDrawingCache();
final Bitmap bitmap = Bitmap.createBitmap(getDrawingCache());
final File file = new File("/sdcard/test.png");
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream);
ostream.close();
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
}
};
WindowManager.LayoutParams screenShotViewLp = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.RGBA_8888);
screenShotViewLp.width = WindowManager.LayoutParams.MATCH_PARENT;
screenShotViewLp.height = WindowManager.LayoutParams.MATCH_PARENT;
screenShotViewLp.gravity = Gravity.LEFT | Gravity.TOP;
wm.addView(screenshotView, screenShotViewLp);