2

I have a rooted device and I successfully capture the screenshot of current screen, using this code:

Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("/system/bin/screencap -p " + path + "; \n");

But in the command I provide the path where I want to save the file and the system takes time to write the image in the file. Can we directly take the image data from process in the form of bytes? I want to send the current image to the server immediately.

4

2 回答 2

0

我认为这也不可能像mah所指出的那样。

下面的代码将帮助您在将图像写入内存时保持应用程序的响应。

这是因为UI/main thread忙于将捕获的屏幕截图写入内存。所以解决这个问题最简单的方法是AsyncTask.

public CaptureScreenShot extends Activity
{
  ArrayList<bitmap> arrayListImage;
  int i=0;

  public void captureScreenshot()
  {
     i++;

     // store the image in arrayList "image"

     new BackgroudClass.execute();
  }

 private class BackgroudClass extends AsyncTask<Void, Void, Void> 
 {
     @Override
     protected Void doInBackgroud(Void.. params)
     {
        // write the image from arrayList at imageArrayList.get(i);
     }
 }


@Override 
public onStop()
{
    arrayListImage = null; // making it eligible for GC
}

希望这可以帮助。

于 2013-09-14T13:53:53.750 回答
0

如果您不提供文件参数,screencap 应该将图像数据打印到标准输出:

用法:screencap [-hp] [-d display-id] [FILENAME]
-h:此消息
-p:将文件保存为 png。
-d:指定要捕获的显示 id,默认为 0。
如果 FILENAME 以 .png 结尾,它将保存为 png。
如果 FILENAME 没有给出,结果将被打印到标准输出。

Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("/system/bin/screencap\n");

然后,您可以从您获得的标准输出中读取图像数据process.getInputStream()

于 2014-03-30T17:27:10.053 回答