2

我想知道是否可以将手机截屏并将其保存在我的图库中。就像 Windows 上的 printscreen 功能一样,Android 上也有类似的功能吗?是否有任何代码可以打印我的应用程序屏幕?

4

2 回答 2

2

这些是可能的方法。

  • 如果你想在eclipse中截取模拟器或连接设备的截图,那么

打开 Android 视图“设备”(在 Window --> Show View --> Other... --> Android --> Devices 下)。单击您要截屏的设备或模拟器,然后单击“屏幕捕获”按钮并将其保存在您想要的任何位置。

  • 如果您想以编程方式截取您的应用程序,请按照此处的答案进行操作:如何以编程方式在 Android 中截取屏幕截图? 这里有一些使用 shell 命令的技巧需要你的手机被 root。

    这是来自上述链接的示例代码。

    // image naming and path  to include sd card  appending name you choose for file
    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + "img_name.jpg";   
    
    // create bitmap screen capture
    Bitmap bitmap;
    View v1 = getWindow().getDecorView().findViewById(android.R.id.content);
    v1.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);
    
    OutputStream fout = null;
    Uri uri = Uri.fromFile(new File(mPath)); //can used as uri
    
    try {
        fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
        fout.flush();
        fout.close();    
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
  • 正如@Shobhit 所说,如果可用,您可以通过制造商快捷方式截取屏幕截图。如果您需要,这里是一些参考:http: //www.makeuseof.com/tag/6-ways-to-take-screenshots-on-android/

于 2013-07-26T19:12:16.547 回答
0

我不确定您是要以编程方式还是手动方式进行。当您说“像 Windows 中的 PrintScreen”时,我假设您想手动截取屏幕截图。您可以在 Android 操作系统随附的不同手机型号中使用不同的按钮组合。如何在 Android博客上截屏列出了您可以在不同型号的 Android 手机上截屏的各种方法。希望这可以帮助。

于 2013-07-26T18:32:43.153 回答