Android开发截屏某控件

public void printScreen(View view) {
    
    
        String imgPath = "/storage/emulated/0/Pictures/test.png";
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap bitmap = view.getDrawingCache();
        if (bitmap != null) {
    
    
            try {
    
    
                FileOutputStream out = new FileOutputStream(imgPath);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100,
                        out);
            } catch (Exception e) {
    
    
                e.printStackTrace();
            }
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_35761934/article/details/121794870