try {
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas();
canvas.setBitmap(bitmap);
v.draw(canvas);
try {
FileOutputStream fos = new FileOutputStream(filePath);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (FileNotFoundException e) {
throw new InvalidParameterException();
}
} catch (Exception e) {
e.printStackTrace();
}
该方法是依托于view的截图方式
想要后台截屏,需要借助MediaProjectionManager的方式实现,即录屏。取出来第一帧