浩晨众云网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本文介绍了Android 实现截屏方式整理,分享给大家。希望对大家有帮助
可能的需求:
1.只截取自己应用内部界面
1.1 截取除了导航栏之外的屏幕
View dView = getWindow().getDecorView(); dView.setDrawingCacheEnabled(true); dView.buildDrawingCache(); Bitmap bitmap = Bitmap.createBitmap(dView.getDrawingCache()); if (bitmap != null) { try { // 获取内置SD卡路径 String sdCardPath = Environment.getExternalStorageDirectory().getPath(); // 图片文件路径 String filePath = sdCardPath + File.separator + "screenshot.png"; File file = new File(filePath); FileOutputStream os = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); os.flush(); os.close(); DebugLog.d("a7888", "存储完成"); } catch (Exception e) { } }