为什么我无法从 /dev/graphics/fb0 读取数据?

发布于 2024-12-03 13:44:03 字数 625 浏览 1 评论 0原文

我正在使用模拟器。所以我肯定有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扶醉桌前 2024-12-10 13:44:03

由于fb0是一个缓冲文件,它是一个不断变化的文件,您应该将其复制到某个可访问的目的地,然后使用FileInputStream读取它,轻松获得正确的数据。

就像:

("cat /dev/graphics/fb0 > /dev/myRawFrame.raw");

File CurrentRawFile = new File("/dev/myRawFrame.raw");

你就完成了:)

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:

("cat /dev/graphics/fb0 > /dev/myRawFrame.raw");

File CurrentRawFile = new File("/dev/myRawFrame.raw");

and you're done :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文