如何使用getDrawingCache捕获带阴影的屏幕截图?

Usm*_*man 5 java android elevation shadow imageview

我在我的应用程序中截取屏幕截图:

private Bitmap takeScreenshot() {
    View rootView = findViewById(android.R.id.content).getRootView();
    rootView.setDrawingCacheEnabled(true);
    return rootView.getDrawingCache();
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但结果不包含任何阴影.如何捕捉高架物体的阴影?

我想我也可以使用一种非常古老的方法制作假影,但这将是一种非常古老的方法,并且会忽略高程和自然阴影的概念.这是我不想要的.

请回复.

谢谢.

Art*_*aev 0

我用过UiDevice.takeScreenshot(File)UIAutomator。

你可以尝试去实现它的方式。它使用仅自 API 18 起可用的UiAutomation 。