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)
TangGeeA 发布了116 篇原创文章 · 获赞 22 · 访问量 9万+ 私信 关注标签:captureView,bitmap,截屏,displayMetrics,new,Android,Bitmap,方法,PixelCopy 来源: https://blog.csdn.net/woai110120130/article/details/104185482