【发布时间】:2014-06-12 08:46:49
【问题描述】:
我使用以下代码在有根设备上截屏:
sh = Runtime.getRuntime().exec("su", null,null);
os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.jpg" + "\n").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
myBitmap = BitmapFactory.decodeFile("/sdcard/img.jpg");
由于我想经常截屏,我不想先将其保存到文件中,然后再读取字节。有没有更好的方法直接获取截图位图?我只是不想消除这种不必要的延迟。 非常感谢!
更新:
screencap.cpp代码可以查看here。
另外,它提到了这一点:
"usage: %s [-hp] [-d display-id] [FILENAME]\n"
" -h: this message\n"
" -p: save the file as a png.\n"
" -d: specify the display id to capture, default %d.\n"
"If FILENAME ends with .png it will be saved as a png.\n"
"If FILENAME is not given, the results will be printed to stdout.\n"
请帮帮我。谢谢!
【问题讨论】:
-
你可以用命名管道做一些事情。
-
@ChrisStratton 谢谢哥们,你能详细说明一下吗?
-
虽然有点晚了,你可以在这里查看我的相关问答:stackoverflow.com/a/29832329/1112789
标签: java android root screen-capture su