如何在Android上以编程方式截取屏幕截图? [重复]

问题描述 投票:11回答:3

这个问题在这里已有答案:

我想以编程方式拍摄全屏截图,例如,Android主屏幕或菜单之一。如何在应用程序中查看主屏幕?我想以编程方式采取它!它是否需要root模式无关紧要!

请帮帮我,抱歉我的英文!

android screenshot
3个回答
13
投票

使用以下代码

Bitmap bitmap;
View v1 = MyView.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

这里MyView是我们需要在屏幕中包含的视图。


6
投票

按照链接https://code.google.com/p/android-screenshot-library/downloads/list,它允许您不仅是您的应用程序的任何屏幕的整个屏幕截图

adb shell / system / bin / screencap -p /sdcard/img.png这是一个shell命令,截屏简单快捷

试试这个

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();

0
投票

在adb shell中,您可以使用命令as

adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png

我在How to take a screenshot on Android上的这个指南中找到了这个代码。你可以参考它来获取更多细节。希望这会有所帮助。

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