Android的抓图从code,以root权限 [英] Android take screenshot from code, with root access

查看:250
本文介绍了Android的抓图从code,以root权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要采取截图在后台运行的服务。屏幕截图可以在前台应用程序,即使它不是我的应用程序,这就是为什么我不能用DrawingCache。我搜索了一圈,发现此

I need to take a screenshot from a service running in the background. The screenshot can be of the app in the foreground, even if its not my app, which is why I can't use DrawingCache. I've searched around and found this

程序=调用Runtime.getRuntime()EXEC(素-c猫的/ dev /图形/ fb0设备)。 InputStream的是= process.getInputStream();

process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0"); InputStream is = process.getInputStream();

但我不知道该怎么办与流。我如何得到它变成一个位图?我不需要将其保存到文件我只需要保持在一个变量。这是根深蒂固的手机。

But I don't know what to do with the stream. How do I get it into a bitmap? I don't need to save it to file I just need to keep it in a variable. This is for rooted phones.

任何帮助是非常AP preciated。

Any help is much appreciated.

推荐答案

唉,看来我对我自己的这一个。到目前为止,这是我发现,对于那些谁也有类似的问题。请注意,这由各个版本,我运行2.3姜饼。

Well, seems I'm on my own with this one. So far this is what I've found, for those who have a similar problem. Note that this varies by version, and I am running 2.3 Gingerbread.

我发现2个文件中的 /系统/斌 - screencap 截图

I found 2 files in /system/bin - screencap and screenshot.

screencap 返回一个位图格式,我不知道该如何去code,而截图做了一个名为tmpshot.bmp在SD卡的根目录常规BMP文件(既不接受任何形式的命令参数。他们似乎不接受-h,-help,--help等任)。

screencap returns a bitmap in a format I don't know how to decode, while screenshot makes a regular bmp file called tmpshot.bmp at the root of the sdcard (Neither accept any kind of command parameters. They don't seem to accept -h,-help, --help etc either).

tmpshot.bmp似乎现在一个可行的解决方案,但我一直在寻找,以避免编写,并从SD卡,因为这是相当的瓶颈读书。我会继续寻找,但对于那些谁需要一个解决方案,现在,给你。

tmpshot.bmp seems a viable solution for now but I was looking to avoid writing and reading from sdcard as this is quite the bottleneck. I will keep searching, but for those who need a solution now, here you are.

编辑:经过进一步的试验,我发现了 screencap从另一个ROM 二进制(MIUI是具体的)实际上提供了更多的选项,其中(MIUI) screencap -t PNG /sdcard/screen.png 产生一个有效的PNG截图。

Upon further trials I found the screencap binary from another rom (MIUI to be specific) actually offers a few more options, where (miui)screencap -t png /sdcard/screen.png yields a valid png screenshot.

这篇关于Android的抓图从code,以root权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆