为什么我无法从 /dev/graphics/fb0 读取数据?
我正在使用模拟器。所以我肯定有root权限。 我使用命令:
adb pull /dev/graphics/fb0 d:/a
,然后使用我的程序读取此文件并生成 bmp。它是成功的。但是当我使用纯java代码来执行此操作时:
Process process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0");
process.waitFor( );
InputStream is = process.getInputStream();
is.read(buffer, 0, width*height*2);
缓冲区获取不到正确的数据。所有数据都是0,而正确的是前几行0xFF。
然后我尝试了:
adb shell
cat /dev/graphics/fb0 > /sdcard/tmp
tmp文件也得到了正确的数据。 为什么纯java代码失败了?我使用 Process 类的方式是否错误?
I am using the emulator. So definitely I have the root permission.
I use command:
adb pull /dev/graphics/fb0 d:/a
and then use my program to read this file and generate a bmp. It is successful. But when I use pure java code to do this:
Process process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0");
process.waitFor();
InputStream is = process.getInputStream();
is.read(buffer, 0, width*height*2);
The buffer can not get the correct data. All the data is 0, while the correct is 0xFF at the first several line.
Then I tried:
adb shell
cat /dev/graphics/fb0 > /sdcard/tmp
The tmp file also got the correct data.
Why the pure java code failed? Is the way I used the Process class wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于fb0是一个缓冲文件,它是一个不断变化的文件,您应该将其复制到某个可访问的目的地,然后使用
FileInputStream
读取它,轻松获得正确的数据。就像:
你就完成了:)
Since the fb0 is a buffer file, it is an always-changing file, you should copy it to a certain ACCESSIBLE destination then read it with
FileInputStream
, easily having the correct data.Like:
and you're done :)