如何使用“屏幕布局”视图拍摄“摄像机”视图的屏幕快照?

时间:2019-04-19 18:52:28

标签: android android-layout android-fragments android-intent

这是我的代码。

public Bitmap takeScreenshot() {
    View rootView = findViewById(android.R.id.content).getRootView();

    rootView.setDrawingCacheEnabled(true);
    return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) throws IOException {

    File imagePath = new File(Environment.getExternalStorageDirectory() + "/Protractor"+count+".png");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e("Mirza", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("Mirza", e.getMessage(), e);
    }
}

0 个答案:

没有答案