Android:如何在rooted设备上获取framebuffer(截图)?

前端之家收集整理的这篇文章主要介绍了Android:如何在rooted设备上获取framebuffer(截图)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试过了 :
process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0 > /sdcard/frame.raw");
process.waitFor();

但它不工作.我的设备是有根的.

我看到许多答案,它需要rooted访问,但没有实际的代码获取framebuffer.

我也试过glReadPixels()但没有运气.

public void TakeScreen() {

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;
        int height = dm.heightPixels;

        int screenshotSize = width * height;
        ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize * 4);
        bb.order(ByteOrder.nativeOrder());
        gl.glReadPixels(0,width,height,GL10.GL_RGBA,GL10.GL_UNSIGNED_BYTE,bb);
        int pixelsBuffer[] = new int[screenshotSize];
        bb.asIntBuffer().get(pixelsBuffer);
        bb = null;
        Bitmap bitmap = Bitmap.createBitmap(width,Bitmap.Config.RGB_565);
        bitmap.setPixels(pixelsBuffer,screenshotSize - width,-width,height);
        pixelsBuffer = null;

        short sBuffer[] = new short[screenshotSize];
        ShortBuffer sb = ShortBuffer.wrap(sBuffer);
        bitmap.copyPixelsToBuffer(sb);

        for (int i = 0; i < screenshotSize; ++i) {
            short v = sBuffer[i];
            sBuffer[i] = (short) (((v & 0x1f) << 11) | (v & 0x7e0) | ((v & 0xf800) >> 11));
        }
        sb.rewind();
        bitmap.copyPixelsFromBuffer(sb);
        saveBitmap(bitmap,"/screenshots","capturedImage");
    }

解决方法

似乎像你的问题是这样的迹象:>您不能使用exec重定向输出.您需要做的是抓取进程的输出流(这是您的输入流)并将其存储到文件中;
process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0");
InputStream is = process.getInputStream();
...

猜你在找的Android相关文章