Android截屏并保存到手机

    xiaoxiao2023-03-24  5

    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(); } } }
    转载请注明原文地址: https://ju.6miu.com/read-1202730.html
    最新回复(0)