截屏保存

// 获取指定Activity的截屏,保存到png文件

private static Bitmap takeScreenShot(Activity activity) {

// View是你需要截图的View

    View view = activity.getWindow().getDecorView();

    view.setDrawingCacheEnabled(true);

    view.buildDrawingCache();

    Bitmapb1 =view.getDrawingCache();

    // 获取状态栏高度

    Rectframe =new Rect();

    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);

    int statusBarHeight =frame.top;

    Log.i("TAG", "" +statusBarHeight);

    // 获取屏幕长和高

    int width = activity.getWindowManager().getDefaultDisplay().getWidth();

    int height = activity.getWindowManager().getDefaultDisplay().getHeight();

    // 去掉标题栏

// Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);

    Bitmapb =Bitmap.createBitmap(b1, 0, statusBarHeight, width, height

            -statusBarHeight);

    view.destroyDrawingCache();

    return b;

}

// 保存指定位置

private static void savePic(Bitmap b, String strFileName) {

try {

FileOutputStream fos =new FileOutputStream(strFileName);

            b.compress(Bitmap.CompressFormat.PNG, 90, fos);

            fos.flush();

            fos.close();

    }catch (Exception e) {

e.printStackTrace();

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容