Android中实现截屏并保存到手机中。AndroidManifest.xml中添加权限:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />MainActivity中调用以下函数:private void printScreen() { View view = getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bmp = view.getDrawingCache(); if (bmp != null) { try { String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "1.png"; File file = new File(path); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } } }
Android截屏并保存到手机
最新推荐文章于 2023-04-10 17:10:03 发布