Android 各种截屏方法

1 应用内截屏(无SurfaceView, TextureView)

boolean cacheEnable = captureView.isDrawingCacheEnabled();
captureView.setDrawingCacheEnabled(true);
captureView.buildDrawingCache();
Bitmap bitmap = captureView.getDrawingCache();
cache[0] = Bitmap.createBitmap(bitmap);
captureView.setDrawingCacheEnabled(cacheEnable);

2 应用内截屏.需要权限android.permission.READ_FRAME_BUFFER

Display display = ((WindowManager)captureView.getContext()
     .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getRealMetrics(displayMetrics);

Bitmap bitmap = SurfaceControl.screenshot(displayMetrics.widthPixels,
     displayMetrics.heightPixels);

3 Android 9.0

    
    PixelCopy.request(window, bitmap, new PixelCopy.OnPixelCopyFinishedListener() {
        @Override
        public void onPixelCopyFinished(int copyResult){
            if (PixelCopy.SUCCESS == copyResult) {
                // onSuccessCallback(bitmap)
            } else {
                // one rrorCallback()
            }
        }
    }, new Handler());

4 读 framebuffer

        String DEVICE_NAME = "/dev/graphics/fb0";
        File deviceFile = new File(DEVICE_NAME);

        Process localProcess = Runtime.getRuntime().exec("supersu");
        String str = "cat " + deviceFile.getAbsolutePath() + "\n";
        localProcess.getOutputStream().write(str.getBytes());
        return localProcess.getInputStream();

5 拼接TextureView (TODO)

Android 各种截屏方法Android 各种截屏方法 TangGeeA 发布了116 篇原创文章 · 获赞 22 · 访问量 9万+ 私信 关注
上一篇:android – TelephonyManager实例化


下一篇:Android 屏幕适配