从后台截图并在保存前处理

Screenshot from background and process it before save

是否可以从后台截取另一个应用程序的屏幕截图并将其转换为位图以在保存之前进行一些更改?设备已植根。

我试过执行控制台命令,但它会自动将文件保存到磁盘,所以我需要读取文件、进行更改(向用户显示)并再次保存(或删除)。所以,要避免先保存。

顺便说一句,是否可以只显示特定区域,而不是全屏?

 No , you need to save the file before any processing is needed to be done on the image before. 
You can one thing is let the file be saved and then with proper permissions you can overwrite the file by :
1. creating a copy
2.making changes
3.deleting the original
4.renaming the changed file

如果您可以制作一个系统应用程序(使用与您的 Android 系统相同的密钥签名的应用程序),那么您可以使用 WindowManagerService.java API screenshotApplications() 其中 returns 一个 Bitmap 的截图。

更多详情请查看WindowManagerService.java source

另一种解决方案可以在 21+ API 的非 root 设备上使用,即使用 MediaProjectionManager.

Here example how to use it and