Android 9:使用带有指定minLayer和maxLayer的SurfaceControl截屏时获取“黑色图像”

问题描述 投票:1回答:1

我正在开发基于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" />

我做错了什么?是否有另一种方法可以捕获具有选定图层的屏幕

android screenshot android-source surfaceflinger
1个回答
0
投票

我无法解决您的SurfaceControl问题。

但是您可以尝试按照以下示例来捕获所需的图层

https://github.com/nitiwari-dev/Blur-behind-alert-dialog

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.