【问题标题】:How to take screenshot of entire screen in Android programmatically?如何以编程方式在Android中截取整个屏幕?
【发布时间】:2013-10-09 19:20:21
【问题描述】:

我需要在Android中截取整个屏幕,我搜索了很多但是他们都说要截取指定视图,我怎样才能截取整个屏幕?

我的意思是,通过程序。(不是通过 DDMS)

【问题讨论】:

  • 这取决于您使用的手机。在少数手机中,您可以同时按住音量减小按钮和电源按钮来截取屏幕截图,该屏幕截图将存储在手机内的屏幕截图文件夹中。我宁愿建议通过 USB 将您的设备连接到系统。通过 Eclipse-->DDMS,您可以在手机上截取当前屏幕的屏幕截图。
  • 我已经编辑了我的答案,并查看了在 Android 上以编程方式截取屏幕截图的链接

标签: android screenshot


【解决方案1】:

有一个库可用于通过设备拍摄快照,称为 ASL(Android Screenshot library)

看看here的完整源代码

【讨论】:

    【解决方案2】:

    在 Eclipse 中转到 DDMS 透视图并选择您的设备。然后点击屏幕截图(相机图片)按钮。

    通过这个link它可能对你有帮助......

    【讨论】:

      【解决方案3】:

      您需要root您的设备,否则它将无法工作。您还必须让您的应用程序获得超级用户访问权限。只需实现此代码,您就可以开始了:

      public void screenShot() throws InterruptedException
      {
          Process sh;
          try
          {
              sh = Runtime.getRuntime().exec("su", null, null);
              OutputStream os = sh.getOutputStream();
              os.write(("/system/bin/screencap -p " + "/sdcard/Image.png").getBytes("ASCII"));
              os.flush();
              os.close();
              sh.waitFor();
          }
          catch (IOException e)
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      
      }
      

      【讨论】:

        【解决方案4】:

        试试下面的代码:

        // image naming and path  to include sd card  appending name you choose for file
        String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   
        
        // create bitmap screen capture
        Bitmap bitmap;
        View v1 = mCurrentUrlMask.getRootView();
        v1.setDrawingCacheEnabled(true);
        bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        v1.setDrawingCacheEnabled(false);
        
        OutputStream fout = null;
        imageFile = new File(mPath);
        
        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();
        }
        

        请参阅此answer

        【讨论】:

        • @Matt_9.0.. mCurrentUrlMask 是什么??
        • @Noman 我发布了link,我实际上是从那里提到了答案。评论中有关于相同的讨论,最后.. Insted of View v1 = mCurrentUrlMask.getRootView(); I have used View v1 = getWindow().getDecorView().getRootView(); and it works for me. 是其中一位用户的评论。所以我认为这可能会奏效。
        • 这种方法似乎只捕获活动布局,而不是状态栏内容或警报等任何覆盖。
        【解决方案5】:

        在 Eclipse 中转到窗口 -> 显示视图 -> 其他 -> 设备

        选择您的设备,然后点击“相机图片”:

        【讨论】:

        • 阅读问题.. !!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 2011-11-22
        • 2016-03-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多