我正在开发基于Android Pie(Android 9)的系统应用。我需要捕获屏幕而不是整个屏幕,我只需要捕获第1层(用于墙纸)到第2层(用于应用程序)。
我这样使用SurfaceControl:
Rect crop = new Rect(0, 0, 1920, 1080);
int width = crop.width();
int height = crop.height();
Bitmap bitmap = SurfaceControl.screenshot(crop, width, height, 1, 2, false, 0);
// "1" is the lowest (bottom-most Z order) surface layer to include in the screenshot
// "2" is the highest (top-most Z order) surface layer to include in the screenshot
但是返回的bitmap
始终是黑色图像。
我的应用程序是系统专用应用程序,已放置在/system/priv-app
中。另外,我已经在AndroidManifest.xml
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
我做错了什么?是否有另一种方法可以捕获具有选定图层的屏幕
我无法解决您的SurfaceControl问题。
但是您可以尝试按照以下示例来捕获所需的图层