安卓:你怎么能得到帧缓冲(截图)上扎根设备?你怎么、截图、设备

2023-09-04 03:52:27 作者:唱⒈半的情歌ゝ

我想:

 程序=调用Runtime.getRuntime()EXEC(素-c猫的/ dev /图形/ FB0> /sdcard/frame.raw)。
process.waitFor();
 

,但它不工作。我的设备是植根。

我看到很多的答案,它需要植根访问,但没有实际code,以获得帧缓冲。

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

 公共无效TakeScreen(){

        DisplayMetrics DM =新DisplayMetrics();
        。getWindowManager()getDefaultDisplay()getMetrics(DM)。
        INT宽度= dm.widthPixels;
        INT高= dm.heightPixels;

        INT screenshotSize =宽*高;
        ByteBuffer的BB = ByteBuffer.allocateDirect(screenshotSize * 4);
        bb.order(ByteOrder.nativeOrder());
        gl.glReadPixels(0,0,宽度,高度,GL10.GL_RGBA,
                GL10.GL_UNSIGNED_BYTE,BB);
        INT pixelsBuffer [] =新的INT [screenshotSize]
        。bb.asIntBuffer()得到(pixelsBuffer);
        BB = NULL;
        点阵位图= Bitmap.createBitmap(宽度,高度,
                Bitmap.Config.RGB_565);
        bitmap.setPixels(pixelsBuffer,screenshotSize  - 宽度, - 宽度,0,0,
                宽度,高度);
        pixelsBuffer = NULL;

        短sBuffer [] =新的短[screenshotSize]
        ShortBuffer SB = ShortBuffer.wrap(sBuffer);
        bitmap.copyPixelsToBuffer(某人);

        的for(int i = 0; I< screenshotSize ++我){
            短V = sBuffer [I]
            sBuffer [I] =(短)(((V&安培; 0x1F的)LT;< 11)|(V&安培; 0x7e0)|((V&安培; 0xf800)>> 11));
        }
        sb.rewind();
        bitmap.copyPixelsFromBuffer(某人);
        saveBitmap(位图,/截图,capturedImage);
    }
 

解决方案 怎么用电脑给Andriod安卓手机屏幕截图

这是不是一个答案。我对以前做这个工作的公司,我不知道他们做了什么,但我知道你不能得到缓冲,仅仅使用一种方法,它依赖于设备的硬件结构。

I tried :

process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0 > /sdcard/frame.raw");
process.waitFor();

but it doesn't work. My device is rooted.

I see many answers that it requires rooted access, but no actual code to get the framebuffer.

I also tried glReadPixels() but no luck.

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, 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, height,
                Bitmap.Config.RGB_565);
        bitmap.setPixels(pixelsBuffer, screenshotSize - width, -width, 0, 0,
                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");
    }

解决方案

This is not an answer. The company I work for did this before, I don't know what they do, but I know you can't get buffer just use one method, it depends on the devices' hardware architecture.