我想要以编程方式获取全屏截图,例如 Android 主屏幕或菜单。如何在我的应用程序中获取主屏幕的视图呢?我希望能够以编程方式实现!如果需要 root 权限也无妨!请帮助我,谢谢!
使用以下代码
Bitmap bitmap;
View v1 = MyView.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
这里的MyView是需要在屏幕上包含的视图。
请点击链接https://code.google.com/p/android-screenshot-library/downloads/list,这个库可以让你截取任何屏幕的截图,不仅限于你的应用程序。
使用以下命令adb shell /system/bin/screencap -p /sdcard/img.png,可以快速简单地进行截图。
试试吧!
Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
/system/bin
目录中没有screencap
文件,因此不适合我的需求。 - Noleshadb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
我在如何在Android上截屏的指南中找到了这段代码。您可以参考它以获取更多详细信息。希望这可以帮助到您。